[undefined, null, NaN].sort();

[undefined, null, NaN].sort();

How not to sort an array in JavaScript

Hey, @philnash.

Great article. I was linked to it by an O’Reilly newsletter.

How not to sort an array in JavaScript

“Array sorting is one of those things you don’t spend too long thinking about, until it stops working for you.” Phil Nash explores just one of these cases, showing you what went wrong and how to fix it.

Anyway, I noticed an issue in the const numberArrayWithUndefined code block. The variable changes and the comment is not correct.

Best,
Steve

Hey @steve9, thanks! And that’s pretty cool I got into the newsletter.

:man_facepalming: on the code mistake though. I’ve fixed it all up now, thank you so much.

Hi @philnash ,
Thanks for the article. I thought sort just work like that. I never actually tried this.