Javascript Array.prototype.sort() ...
… by default converts the array elements into strings and sorts them by their UTF-8 Codepoints 🤪!
[-7, 2, 10, -1].sort()
[-1, -7, 10, 2]You can pass a function to sort to override the behavior:
[-7, 2, 10, -1].sort(function(a,b){ return a - b })
[-7, -1, 2, 10]Phew.