this post was submitted on 05 Sep 2023
913 points (98.7% liked)

Programmer Humor

19589 readers
550 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Konlanx@feddit.de 56 points 1 year ago (3 children)

This is due to the default sorter in JavaScript sorting by the string value. The reason for that is that this won't create errors at runtime. Since JavaScript does not have types, this is the safest way of sorting.

This works:

const unsorted = [1, 100000, 21, 30, 4]
const sorted = unsorted.sort((a, b) => a - b) 
[–] jmcs@discuss.tchncs.de 66 points 1 year ago (1 children)

Which is a fine decision if you have a programming language to do silly stuff on a personal geocities page, but a horrible one when you start using that language to handle serious data. Silently ignoring what's probably a bug is dangerous.

[–] seitanic@lemmy.sdf.org 25 points 1 year ago (1 children)

Which is a fine decision if you have a programming language to do silly stuff on a personal geocities page

And that is, of course, what it was designed for.

JS is brilliant considering that it was created by one dude in 10 days. Nobody thought it would become nearly as important as it has become.

[–] luciferofastora 1 points 1 year ago

Nobody thought it would become nearly as important as it has become.

This is why I'm wary about all the quick and easy "temporary" solutions I'm building because I don't have the time to do it properly, and pushing hard to replace them with a more solid permanent one at any chance. I'm already mortified at the idea of someone proficient ever looking at any of it in the inevitable event of it becoming a long-term fixture.

[–] UndefinedIsNotAFunction@programming.dev 11 points 1 year ago* (last edited 1 year ago)

Get out of here with your sensibility!

^kidding, ^js ^via ^ts ^is ^my ^life.

[–] AVincentInSpace@pawb.social 1 points 11 months ago* (last edited 11 months ago)

ah yes, a reasonable solution to that problem that any human would think of

ah yes, a reasonable problem that any human would think of -- "what if someone tries to sort a list containing some integers and some arrays, and our interpreter needs to keep chugging instead of telling the programmer they fucked up?"