7

Array.sort Sorting Stability in Different Browsers

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/

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")
Community
  • 1
  • 1
georg
  • 211,518
  • 52
  • 313
  • 390
  • Not sure it fits the site, but I added my results too. – gdoron May 10 '13 at 09:44
  • Someone should probably make a table out of all this. :) – Anirudh Ramanathan May 10 '13 at 09:45
  • 1
    +1 For making me look up what a ["stable sort"](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability) actually is. – nnnnnn May 10 '13 at 09:48
  • @DarkCthulhu: [No tables](http://meta.stackexchange.com/q/16356/183280) :-( But I'll try something – Bergi May 10 '13 at 10:03
  • 1
    It's not clear what value this information provides. Since Array.sort is not guaranteed to be stable, why does it matter which implementations seem to offer stability? The behavior is not guaranteed, so you cannot rely on it. – Raymond Chen May 12 '13 at 21:01

3 Answers3

8
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

albertjan
  • 7,739
  • 6
  • 44
  • 74
georg
  • 211,518
  • 52
  • 313
  • 390
  • This would be easier to read if it was sorted by browser. Basically Firefox has stable sorting, everything else uses unstable sorting. – Joachim Sauer Jul 26 '13 at 06:21
0

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

user123_456
  • 5,635
  • 26
  • 84
  • 140
0

On 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

Dek Dekku
  • 1,441
  • 11
  • 28