The code I found to sort a list of numbers by ascending order is:
arr.sort((a,b) => a-b);
I don't understand how the compare function works. What if you do arr.sort((a,b) => a+b)?
The sort function uses the sign of the value returned by the comparator:
So a - b is just a neat shorthand which fulfills those cases.
(a,b) => { if (a < b) return -1; else if (a > b) return 1; else return 0; }