Can someone explain the purpose of double negating reversevar in the code below?
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 :
(A > B) ? +1 : 0)) * [-1,1][+!!reverse];
}
As I understand it, the goal is to select the correct index from the array [-1,1], then to use it in multiplication, but it seems to me that [-1,1][+!!reverse];you can safely replace it with[-1,1][+reverse];
Am I really wrong? What do you get or prevent by double negation reversethere?
I saw the above code on this answer.
source
share