3 ms·
The sort function is fine when used as intended (for alphabetic sorting). If you want numeric sorting you use sort(function(a,b){return a-b}). [1,10,5,-15,-2,4
by Kiro 13y ago
The sort function is fine when used as intended (for alphabetic sorting). If you want numeric sorting you use sort(function(a,b){return a-b}).
[1,10,5,-15,-2,4].sort(function(a,b){return a-b});
[-15, -2, 1, 4, 5, 10]
- rdtsc 13y agoOk but if I wanted to use alphabetic sorting I would have used ["1","10","5","-15"] no? Wouldn't that make more sense.