Sorting in JavaScript
Comes up in: DSA, JavaScript, Recruiter screen
This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.
What it covers
Array.prototype.sortis stable (required since ES2019)- V8 uses TimSort (since V8 7.0)
- default sort compares strings
- comparator contract (negative/zero/positive, consistent)
- sorting objects by multiple keys
toSortedlocaleCompare/Intl.Collator
Words you will know
What you will practise
- multi-key sort
- fix 4 comparator bugs
Interview questions this answers
- What does it mean for a sort to be stable? Is JavaScript's sort stable?