7

Array.sort 在不同浏览器中的排序稳定性

这是一个老问题,我认为如果我们在这里收集最新数据会很有帮助。请点击这个小提琴

http://jsfiddle.net/Wrt9R/

并分享您的结果。

小提琴代码:

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")
4

3 回答 3

8
稳定性浏览器操作系统完整 UA 字符串

不稳定    的 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
不稳定    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
不稳定    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
不稳定    IE 9.0 Win 7 x64 Mozilla/5.0 (兼容; 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)
稳定      Firefox 20 Win 7 x64 Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
不稳定    IE 10 Win 7 Mozilla/5.0 (兼容; 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)
不稳定    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
不稳定    IE 10 Win 8 x64 Mozilla/5.0(兼容;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)
不稳定    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
不稳定    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
不稳定    Chrome 26 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31
不稳定的    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
不稳定    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

于 2013-05-10T09:40:30.577 回答
0

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 UNSTABLE

于 2013-05-10T09:47:16.513 回答
0

在 IE10 Win7 x64 上:

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) 不稳定

于 2013-05-10T10:34:56.830 回答