I have this sorting function, but which i use to sort a table, i can sort by dates (which i have removed for simplicity) and strings, but intergers are acting wierd, a common case is that all values could be 0, which will give the array
[0,0,0,0]
this works perfectly in firefox but not in chrome, it changes the order of the rows in my table although they are equal, i have even followed the ECMA standards. Why do chrome change the order anyway? I have also tried using
return (ascending_order ? a - b : b - a)
But with the same result as my more general approach to work with different data types
arr.sort(function(a, b){
var onlydigitsRegex = new RegExp("\d+","g");
if (a.match(onlydigitsRegex) && b.match(onlydigitsRegex)) {
a = parseInt(a);
b = parseInt(b);
} else {
a = a.toLowerCase();
b = b.toLowerCase();
}
return (a === b) ? 0 : (ascending_order ? ((a > b) ? 1 : -1) : ((a < b)? 1 : -1));
});