I noticed IE9 sort order is changing elements order when comparison function returns 0.
See:
var myarray=[
{id:1,val:0},
{id:2,val:0},
{id:3,val:7},
{id:4,val:41}
];
myarray.sort(function(a,b){return a.val - b.val});
for(var i in myarray)
{
console.log(myarray[i].id);
}
Current stable versions of Chrome, Firefox, Opera and Safari got the following output: 1 2 3 4.
Same output for IE7 and IE8.
IE9 output is: 2 1 3 4
Why? Is that normal?
From MDC (emphasis mine):
In my experience, only Chrome/Firefox get this right. Opera 11’s behavior for me is .. not well defined.
E.g., using sort to move all zeroes to the top of the array: