Comment on I'll just sort it myself

<- View Parent
ImpossibleRubiksCube@programming.dev ⁨1⁩ ⁨year⁩ ago

JavaScript is what’s called an “untyped” language, so here, it assumes that the numbers are words, and tries to sort them alphabetically. Specifically, it tries to sort them alphabetically as a dictionary would in a left-to-right language like English. In this case, just as “apple” would come before “asterisk”, 100000 would come before 21.

(Some would argue that it’s more of a “weakly typed” language, I know, but I’m trying not to be pedantic here.)

Sorting them as actual numbers would require some extra explicit instructions and guides. Most typed languages, like C, aren’t like this.

source
Sort:hotnewtop