Algorithms and Data Structures · Junior · Question 35 of 75
What should the comparator (a, b) => ... return for sort to put a before b?
- 1A positive number
- 2Zero
- ✓Correct answer: A negative number
Explanation
A negative value means a goes first, a positive value means b goes first, and zero keeps their relative order. That's why (a, b) => a - b sorts numbers in ascending order.