Here is my script:
alert("why isn't this sorted right? #{["6","7","2","11","10","9","4","5","3","8","1"].sort
(a,b) -> +a < +b }")
You can try running here .
The result will be:
Why is this not right? 9,6,8,11,10,7,5,4,3,2,1
My question is why? I expect the answer to be 11, 10, 9, 8, ....
This is probably due to strings and numbers, but "+" forces the string to a number, and in any case, the result is not correct for even comparing strings. It just seems random.
source
share