$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #82

What is the correct fix?

const nums = [5, 1, 10];
nums.sort((a, b) => a > b);
  1. Return a number: (a, b) => a - b
  2. Return a number: (a, b) => a < b
  3. Drop the comparator and call sort()
  4. Wrap the result in Number(a > b)
A comparator must return a negative, zero or positive number, not a boolean.
Play Problem Solving ▸