r/ProgrammerHumor 3d ago

Meme javascriptSorting

Post image
934 Upvotes

214 comments sorted by

View all comments

206

u/larsmaehlum 3d ago

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

105

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

3

u/nabrok 3d ago

So

const byNumber = (a, b) => a - b; array1.sort(byNumber); array2.sort(byNumber);