rendakuenthusiast:

thathopeyetlives:

cromulentenough:

thathopeyetlives:

terdragon:

This was the bug in my code once.

Bwah? As someone who knows no JavaScript…

i’m guessing if you put 09 it would do it fine, but it’s sorting first digit by first digit? Windows file systems do that in names of files when sorting alphabetically but i would have thought an actual programming language would do better…

Is Javascript one of those “everything is a string” languages?

Not quite, but it does do number string type coercions in unexpected places. I honestly have no idea why it makes sense that .sort() has this behavior off the top of my head. The correct solution is to use the underscore.js sorting functionality and not even think about what the built in methods do.

I honestly have no idea why it makes sense that .sort() has this behavior

Purely guessing here, sort() probably works on arrays that have strings. If it does work on arrays of strings, it might automatically coerce everything into a string instead of first checking whether that’s appropriate.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s