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

Which fix removes the bug?

const sorted = [10, 9, 100].sort();
console.log(sorted);
  1. Pass (a, b) => a - b to sort
  2. Call reverse() after sort
  3. Convert the array with map
  4. Replace sort with toSorted
Default sort compares strings, so 100 lands before 9 without a comparator.
Play Problem Solving ▸