3 ms·
Because that's a fairly reasonable way of handling array items of unknown type. For example: what should `['1', 2]` do? What about `['1e2', 2]`? `['1_000', 2]`?
by lhorie 7y ago
Because that's a fairly reasonable way of handling array items of unknown type. For example: what should `['1', 2]` do? What about `['1e2', 2]`? `['1_000', 2]`? `['0x3', 2]`? `[true, 2]`, etc.
For numerical sort, pass an callback specifying a numerical sort: `array.sort((a, b) => a - b)`