Didn’t belive it. tried it. died a little more inside.
From MDN:
If compareFn is not supplied, all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order.
So, if you’re trying to sort numbers, [6, -2, 2, -7].sort((a, b) => a - b)
Its converting numbers to strings.
Imagine going for a JavaScript coding interview and failing because of this 😂
Blessed are those that use Array.sort
without passing it arguments