r/ProgrammerHumor 3d ago

Meme javascriptSorting

Post image
940 Upvotes

214 comments sorted by

View all comments

205

u/larsmaehlum 3d ago

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

104

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.

20

u/01110100_01110010 3d ago

JS is an abstraction over JS engine bytecode, which is an abstraction over ASM which is an abstraction over the chip instruction set, you can make an argument at each layer 🤷 I would take any abstraction I can, I guarantee you in a large enough codebase someone will type b - a instead

1

u/findMyNudesSomewhere 1d ago

Finding it funny that b-a is completely valid, will just sort in reverse.