简体   繁体   中英

Sorting : is it browser specific

When I did sort by title for a set of array values, it gives me 3 different results in Safari,Chrome and Firefox. Why the behaviour is so? I used sproutcore framework. I have used

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

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

record1.localeComapre(record2)

How do you know that you're getting different results?

The experience of other folks suggests that the behavior of localeCompare deviates between the browsers. See http://blog.schmichael.com/2008/07/14/javascript-collation-fail/ for example, as well as http://code.google.com/p/v8/issues/detail?id=459

Without seeing in more detail how your comparator works, I can't suggest more at this time. You could write a quick-and-dirty check afterwards and confirm that the lists are truly sorted; if the results come out positive, then the differences can be attributed to the quirks of localeCompare or the stability of the sorting routine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM