Which fix removes the bug?
const sorted = [10, 9, 100].sort(); console.log(sorted);
- Pass
(a, b) => a - bto sort - Call
reverse()after sort - Convert the array with
map - Replace
sortwithtoSorted
Default sort compares strings, so 100 lands before 9 without a comparator.
Play Problem Solving ▸