How to Sort Your Socks Using JavaScript
summary
Provides working JavaScript implementations of insertion sort, merge sort and quicksort (including extending Array.prototype), and runs in-browser benchmarks on a Mac Chrome build. Reports that insertion sort outperforms the native Array.sort for very small arrays (tests up to 100k), quicksort can beat the native sort for millions of items, and that different JS engines use different algorithms so stability and equal-key ordering varies.
AI-written summary · about
chapters (15)
- 0:00Welcome
- 1:07Sorting algorithms
- 2:30Native JS sort
- 4:15JS sort internals
- 5:59Small array sorts
- 7:01Sort stability
- 8:23Insertion sort
- 9:50Merge sort
- 12:24Quick sort
- 14:11Implement your own
- 15:33Divide and conquer
- 16:17Stability impact
- 18:02JS sort performance
- 20:12Benchmarking sorts
- 21:59Conclusion
related talks
28mHow to sort your socks using Javascript
24mCS101 Intro to Computational Complexity: The Sorting Problem
57mDown the Rabbit Hole: JavaScript in Wonderland
34mJavaScript is an Oddball
39mHow much performance can you get out of Javascript?
24mDown the Rabbit Hole: Javascript in Wonderland
43mJavaScript in 2026
46mHow much performance can you get out of JavaScript?
