$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #162

Which fix removes the bug?

const sorted = [10, 9, 1].sort();
console.log(sorted);
  1. Pass a compare function
  2. Call reverse afterwards
  3. Map to numbers first
  4. Use toSorted instead
The default sort compares stringified values, so 10 sorts before 9.
Play Problem Solving ▸