[英]Array.sort stability in different browsers
Array.sort Sorting Stability in Different Browsers Array.sort在不同浏览器中排序稳定性
this is an old question, I think it would be helpful if we collect the most recent data here. 这是一个老问题,我认为如果我们在这里收集最新数据会有所帮助。 Please click this fiddle 请点击这个小提琴
http://jsfiddle.net/Wrt9R/ http://jsfiddle.net/Wrt9R/
and share your results. 并分享您的结果。
Fiddle code: 小提琴代码:
a = []
for(var i = 0; i < 1000; i++) {
a.push({'key':100 + Math.round(Math.random() * 100), 'val': i + 1000 })
}
a.sort(function(x, y) { return x.key - y.key })
b = []
for(var i = 0; i < 1000; i++) {
b.push(a[i].key * 10000 + a[i].val);
}
c = b.slice(0)
b.sort()
stable = (b.join() === c.join())
document.body.innerHTML = navigator.userAgent.toString() + "<br>" + (stable ? "stable": "UNSTABLE")
Stability Browser OS full UA string unstable Safari 5.3 OS X Lion (10.7.5) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13 stable Firefox 15.0.1 OS X Lion Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20100101 Firefox/15.0.1 unstable Chrome 21 OS X Lion (10.7.5) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1 stable Firefox 16 Win 7 Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0 unstable Chrome 26 Win 7 x64 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 unstable IE 9.0 Win 7 x64 Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E) stable Firefox 20 Win 7 x64 Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0 unstable IE 10 Win 7 Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3; .NET4.0C; .NET4.0E) unstable Chrome 26 Win 7 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 stable Firefox 20 Win 8 x64 Mozilla/5.0 (Windows NT 6.2; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0 unstable IE 10 Win 8 x64 Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0) unstable Chrome 26 Win 8 x64 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 unstable Opera 12.15 Win 8 x64 Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.15 stable Firefox 20 Ubuntu Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0 unstable Chrome 26 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31 unstable Chrome 20 Win 7 x64 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 unstable Chrome 28 Win 8 x64 Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 536.11(KHTML,如Gecko)Chrome / 20.0.1132.57 Safari / 536.11 UNSTABLE
On IE10 Win7 x64: 在IE10 Win7 x64上:
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPNTDF; .NET4.0C) UNSTABLE Mozilla / 5.0(兼容; MSIE 10.0; Windows NT 6.1; WOW64; Trident / 6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPNTDF ;. NET4.0C)不稳定
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.