I have an array of float point numbers:
[ 82.11742562118049, 28.86823689842918, 49.61295450928224, 5.861613903793295 ]
After running sort() on the array I get this:
[ 28.86823689842918, 49.61295450928224, 5.861613903793295, 82.11742562118049 ]
Notice how 5.8... is bigger than 49.6... for JavaScript (Node). Why is that?
How can I correctly sort this numbers?
arr.sort(function (a, b) { return a-b; });. As it stands, the values are being sorted alphabetically. "2" comes before "4", which comes before "5", which comes before "8" (the comparison is the first "letter" of each number...until they match, then it compares the next letter, and so on)