3 ms·
Demanding a stable Array.sort is surprising. I find it questionable, as it implies a performance trade-off. Why not add a new stableSort function? Trying to re
by heisenhuegel 7y ago
Demanding a stable Array.sort is surprising. I find it questionable, as it implies a performance trade-off. Why not add a new stableSort function?
Trying to retroactively fixing bugs in code that did not follow the standard is not a good idea IMHO.
- masklinn 7y agoThe "stable Array.sort" proposal was actually made because all major browsers had switched to a stable sort implementation: https://github.com/tc39/ecma262/pull/1340 https://github.com/tc39/ecma262/pull/1340 It was actually proposed by the v8 / chrome people (https://v8.dev/features/stable-sort https://v8.dev/features/stable-sort) after they'd finally come around to implement one of the oldest v8 feature requests: https://bugs.chromium.org/p/v8/issues/detail?id=90 https://bugs.chromium.org/p/v8/issues/detail?id=90 And stable does make for a better default than unstable: it offers stronger guarantees and more reliable behaviour. That's doubly important because by and large developers work to the implementation not the spec. And it's unlikely you'll ever change that. The last one to switch was Chakra (Edge), and that one was weird as it used a stable sort up to 512 elements, and unstable above. Funnily enough, Mozilla had originally switched to a stable sort because MSIE used a stable sort: https://bugzilla.mozilla.org/show_bug.cgi?id=224128 https://bugzilla.mozilla.org/show_bug.cgi?id=224128