0
Basic array sort() lesson
Good afternoon! My question is: why the sort() is considering 10 to come first than 5? He is sorting like alphabetic sorting of windows explorer instead of considering the value. How can I fix this? Thank you for your time! https://code.sololearn.com/Wc2TVtKbivt9/?ref=app
2 Answers
+ 2
By default sort is a lexicographic.
To sort numerically you have to pass it a function.
.sort(function (a, b) { return a - b; })
0
Got it! Thank you very much!