问题描述
我知道ECMA脚本规范没有指定用于排序数组的算法,也没有指定排序是否应该稳定。
I know that the ECMA Script specification does not specify which algorithm to use for sorting arrays, nor does it specify whether the sort should be stable.
我是找到指定firefox使用稳定的排序。
I've found this information for Firefox which specifies that firefox uses a stable sort.
有没有人知道IE 6/7/8,Chrome和Safari?
Does anyone know about IE 6/7/8, Chrome and Safari?
推荐答案
(忽略标题,如果引擎的排序稳定,第二组数字应该是顺序的。)
Simple test case (ignore the heading, second set of numbers should be sequential if the engine's sort is stable).
IE的排序一直稳定,只要我使用过它(所以IE6)。再次检查IE8,似乎仍然如此。
IE's sort has been stable as long as I've ever used it (so IE6). Checking again in IE8 and it appears to still be the case.
虽然你链接到的Mozilla页面说Firefox的排序是稳定的,但我肯定地说在Firefox 2.0之前(包括)并不总是如此。
And although that Mozilla page you link to says Firefox's sort is stable, I definitely say this was not always the case prior to (and including) Firefox 2.0.
一些粗略的结果:
- IE6 +:稳定
- Firefox< 3:不稳定
- Firefox> = 3:稳定
- Chrome< 70:不稳定
- Chrome> = 70:稳定
- Opera< 10:不稳定
- Opera> = 10:稳定
- Safari 4:稳定
- 边缘:长阵列不稳定
- IE6+: stable
- Firefox < 3: unstable
- Firefox >= 3: stable
- Chrome < 70: unstable
- Chrome >= 70: stable
- Opera < 10: unstable
- Opera >= 10: stable
- Safari 4: stable
- Edge: unstable for long arrays
Windows上的所有测试。
All tests on Windows.
参见:
这篇关于Array.sort()方法在不同浏览器中的稳定性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!