Array.prototype.sort
stabilityIt looks like your browser’s Array#sort
implementation is unstable when tested using an array of n elements. Try >512 elements.
This page contains a list of doggos, ordered by their official WeRateDogs™ rating. If puppers with the same rating (e.g. rating=13
) are ordered alphabetically by name in the output below, then your browser’s Array#sort
implementation is most likely stable.
Previously, V8 used an unstable QuickSort for arrays with more than 10 elements. As of V8 v7.0 / Chrome 70, V8 uses the stable TimSort algorithm. 🎉
The only major engine JavaScript engine that still has an unstable Array#sort
implementation is Chakra, which uses QuickSort for arrays with more than 512 elements (and stable insertion sort for anything else).
— @mathias