Now I know this will be a stupid question to many, but I cannot understand this logic. So, here is the problem in short:
var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});
Now suppose, values 40 and 100 are compared, so the compare function returns a negative value, i.e -60. So, 40 is placed before 100. Understood.
Now, I do this:
var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return b-a});
Again, if 100 and 40 are compared, the compare function returns a positive value, i.e 60. Now, shouldn't it place 100 after 40 because of that positive returned value? But it doesn't, and I am not getting that.
I just want to know what is happening here.
function(a, b){ if (b > a) return -1; if (b < a) return 1; return 0; }.