The Sort
JavaScript Array.sort
default algorithm:
The callback
Sort callback: comparefn(a, b)
The sort must be stable (that is, elements that compare equal must remain in their original order). If
comparefn
is not undefined, it should be a function that accepts two argumentsx
andy
and returns a negative Number ifx < y
, a positive Number ifx > y
, or a zero otherwise.
- ECMAScript Language Specification3
So the comparefn
expect you to return negative number, zero, or positive number.
But you can return any other type without any error (runtime or default linter setting).
Firefox and Chromium/Node have a difference arguments order (reversed):
Left is firefox console, right is edge console.