4 ms·
> [1,10,5,-15,-2,4].sort(); > [-15,-2,1,10,4,5] [1,10,5,-15,-2,4].sort(function(a,b){return a-b}) [-15, -2, 1, 4, 5, 10]
by bartl 13y ago
> [1,10,5,-15,-2,4].sort();
> [-15,-2,1,10,4,5]
[1,10,5,-15,-2,4].sort(function(a,b){return a-b})
[-15, -2, 1, 4, 5, 10]
- rdtsc 13y agoSo it is broken. I already gave it a list of numbers. Why do I have to subtract them to tell it how to compare them. If I wanted to compare string I would have used ["1","10",....].