85
top 7 comments
sorted by: hot top controversial new old
[-] Seigest@lemmy.ca 28 points 1 year ago

Didn't belive it. tried it. died a little more inside.

[-] poopsmith@lemmy.world 18 points 1 year ago

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)

[-] Solumbran@lemmy.world 4 points 1 year ago

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

[-] _sideffect@lemmy.world 13 points 1 year ago

Imagine going for a JavaScript coding interview and failing because of this 😂

[-] skates@sh.itjust.works 4 points 1 year ago

That's a good point lol, I haven't done a js interview yet but it'd probably be kinda rough trying to remember random shit like this.

[-] EatMyDick@lemmy.world 1 points 1 year ago* (last edited 1 year ago)

Meh, it's a day 2 thing to understand how shitty JS deals with numbers. Good devs will cover their asses by default.

[-] sulungskwa@lemmy.world 9 points 1 year ago

Blessed are those that use Array.sort without passing it arguments

load more comments
view more: next ›
this post was submitted on 21 Jul 2023
85 points (100.0% liked)

Programming Humor

2662 readers
4 users here now

Related Communities !programmerhumor@lemmy.ml !programmer_humor@programming.dev !programmerhumor@kbin.social !programming_horror@programming.dev

Other Programming Communities !programming@beehaw.org !programming@programming.dev !programming@lemmy.ml !programming@kbin.social !learn_programming@programming.dev !functional_programming@programming.dev !embedded_prog@lemmy.ml

founded 1 year ago
MODERATORS