Hi Greg!,

Now it’s explained in a better way. Thanks for you comment!

Array.Sort Stability

Previously, V8 used an unstable QuickSort for arrays with more than 10 elements. V8(Chrome ≥70) uses the stable TimSort algorithm.

The array is pre-sorted alphabetically by name. To sort by age instead we pass a custom callback that compares the ages. This is the result that you’d expect:

The array is sorted by age, but within each age, they’re still sorted alphabetically by name.

Before, the JavaScript specification didn’t require sort stability for Array.sort, and instead left it up to the implementation. And because this you could also get this sort result where “b” appears before “a”:

Written by

Software engineer - software Enthusiast - Sci-Fi writer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store