Array#sort() implementations not interoperable
mathias at qiwi.be
Thu Jun 13 06:05:41 PDT 2013
Bumping this old thread since V8 issue #90 (https://code.google.com/p/v8/issues/detail?id=90) has been getting lots of comments lately.
It appears that unstable sort, while perfectly spec-compliant, doesn’t match user expectations. It doesn’t help that some browsers/engines _do_ use a stable sorting algorithm, while others don’t — which surprises people and occasionally breaks (badly-written, but hey) code. (See the thread I linked to for examples.) Then, there’s V8, which uses stable sort for small arrays with 10 or fewer elements, but an unstable sorting algorithm for larger arrays, causing even more confusion.
Here’s a test case that tests arrays of varying sizes: http://ofb.net/~sethml/is-sort-stable.html The results in different browsers are listed, too.
IMHO it would be nice if ES would require a stable sorting algorithm: it would match user expectations, cause fewer issues in existing code, and improve operability in general.
What would be the best way to make TC39 consider this change?
More information about the es-discuss