Which fix removes the bug?
const sorted = [10, 9, 1].sort(); console.log(sorted);
- Pass a compare function
- Call
reverseafterwards - Map to numbers first
- Use
toSortedinstead
The default sort compares stringified values, so 10 sorts before 9.
Play Problem Solving ▸