@2e8a9d6bb6935a54M to Programming HumorEnglish • 1 year agoJavascript sort is the best sortimagemessage-square9arrow-up186arrow-down13
arrow-up183arrow-down1imageJavascript sort is the best sort@2e8a9d6bb6935a54M to Programming HumorEnglish • 1 year agomessage-square9
minus-square@poopsmithlinkEnglish18•1 year agoFrom 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)
minus-square@SolumbranlinkEnglish4•1 year agoThat might be explainable, but doesn’t make it logical or acceptable.
From MDN:
So, if you’re trying to sort numbers,
[6, -2, 2, -7].sort((a, b) => a - b)
That might be explainable, but doesn’t make it logical or acceptable.