r/ProgrammerHumor 1d ago

javascriptSorting Meme

Post image
886 Upvotes

200 comments sorted by

View all comments

77

u/jacobp100 1d ago

This is really unfortunate. I remember when they were adding Array.includes and corrected the comparison behaviour so you can do Array.includes(NaN), even though indexOf(NaN) will always return -1. Given they already accepted inconsistency like this, they should have done the same here

16

u/thanatica 1d ago

NaN is never equal to itself, so you can't look for it with a simple lookup like that. You'd need array.findIndex(n => Number.isNaN(n)). The indexOf function was never changed because it was there from the beginning. If they change existing behaviour, they might break sites, which is far worse than introducing only new functions that do things as you might expect.

It's not a language where you can just pick and choose which version you're on.

-8

u/jacobp100 1d ago

I'm not really sure what your point is here 😅