Sort: is there a browser

When I sorted by header for a set of array values, it gives me 3 different results in Safari, Chrome and Firefox. Why is this behavior? I used sproutcore framework. I used

Array.sort(function(a,b){return function2(parameter1,parameter2,parameter3,parameter4)}) 

function2 compares my keyValue . function2 in turn calls another comparison function to compare the record values. This function returns 1 , -1 or 0 based

 record1.localeComapre(record2) 
+4
source share
1 answer

How do you know that you have different results?

Other people's experience suggests that localeCompare behavior deviates between browsers. See http://blog.schmichael.com/2008/07/14/javascript-collation-fail/ , as well as http://code.google.com/p/v8/issues/detail?id=459

Without seeing in more detail how your comparator works, I cannot offer more at this time. After that, you can write a quick and dirty check and confirm that the lists are really sorted; if the results are positive, then the differences may be due to the quirks of localeCompare or the stability of the sorting procedure.

+2
source

Source: https://habr.com/ru/post/1388089/


All Articles