Algorithms and Data Structures · Junior · Question 37 of 75
What does a stable sort guarantee?
- ✓Correct answer: Equal elements keep their original relative order
- 2The sort always runs in O(n log n), even in the worst case
- 3The sort never throws, whatever the comparator returns
Explanation
Stability matters when you sort by several keys: sort users by name, then stably by age, and users of the same age stay ordered by name. Array.prototype.sort has been required to be stable since ES2019.