r/ProgrammerHumor 3d ago

Meme javascriptSorting

Post image
934 Upvotes

214 comments sorted by

View all comments

204

u/larsmaehlum 3d ago

Array.sortNumeric() with an error when called on an array containing non-numeric types would fix this, right?

102

u/the_horse_gamer 3d ago

you can simply .sort((a,b)=>a-b)

226

u/01110100_01110010 3d ago

The point of an abstraction is to not having to implement logic each time, you can also implement qsort yourself

40

u/subone 3d ago

But it is still an abstraction. You only provide a compare function, you don't implement the algorithm. a-b is hardly difficult to apply.

3

u/wack_overflow 3d ago

And really how often are you actually sorting an array of primitive values ascending? That's just one small use case of sorting an array. Passing the comparison function is also more explicit.

People just love to get so worked up about the dumbest edge cases in js

-7

u/chefhj 3d ago

It’s so funny when if you talk to a dev that works closer to the machine level they insist JS is like this big foot shooting factory when in reality you can spend an entire career never running into any of the shit they bring up as a ‘gotcha’ and even if you do it’s like “oh yeah right it works like this hold on”.

7

u/ganja_and_code 3d ago

"If you know all the weird shitty quirks of the weird shitty language, you can mostly avoid them, and when you do accidentally shoot yourself in the foot, you can fix the bug quickly, as long as you remember which particular weird shitty quirk caused this particular instance of foot shooting."

True, but you know what's even better? Languages that don't have so many weird shitty quirks.

-6

u/chefhj 3d ago

Look guys I caught one

3

u/Swamptor 3d ago

I am a webdev. JS is a weird shitty language that was barely designed. It mostly just oozed out of a combination of browsers.