this post was submitted on 21 Jul 2023
83 points (96.6% liked)

Programming Humor

2763 readers
3 users here now

Related Communities [email protected] [email protected] [email protected] [email protected]

Other Programming Communities [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 18 points 1 year ago (1 children)

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)

[โ€“] [email protected] 4 points 1 year ago

That might be explainable, but doesn't make it logical or acceptable.