.sort()
Hi guys I try sorting my array, and unfortunately I was not able to return it in a particular a-z
3 Replies
See my "e-waste" is placed at index 10
should be after C isn't it?
Array.sort()
uses the ASCII table by default, so capital and lowercase letters are in different places
Your capital letters are sorted first, followed by lowercase letters because that's the numerical sort order. Capital C
, for example, is ASCII number 67 while lowercase c
is ASCII number 99
What you want is case-insensitive sorting so you'll have to write your own sorting function that either changes all letters to caps or to all lowercase
For example, if you pass this function as the argument to your .sort()
it'll sort them alphabetically:
I see, that's definitely helpful thanks man