The HOST (Browser) when it comes to ECMAScript standard does not follow the policy of "implementation defined". This means that the behavior of Array.prototype.sort method may be different between engine implementations. Please refer to official documentation under these links:
https://tc39.es/ecma262/#sec-array.prototype.sort
https://tc39.es/ecma262/#implementation-defined
If you want o achieve a consistent behavior of sorting between browsers that is not obvious you should map the array to an indexed object. In this case both Chrome and Firefox result in same iteration over indexes and values.
var arr = [3,1,2];
var sorted_arr = arr.sort(function(a,b) {
console.log("a, b = ", a, b);
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
// a must be equal to b
return 0;
});
console.log("sorted_arr: ", sorted_arr)
var mapped = arr.map(function(el, i) {
return { index: i, value: el.toString().toLowerCase() };
})
mapped.sort(function(a, b) {
console.log("map: ", a, b)
if (a.value > b.value) {
return 1;
}
if (a.value < b.value) {
return -1;
}
return 0;
});
// container for the resulting order
var result = mapped.map(function(el){
return arr[el.index];
});
console.log("result: ", result)
https://jsfiddle.net/cw65b4t8/