Can someone please explain the purpose of double-negating the reverse
var in the below code?
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 :
(A > B) ? +1 : 0)) * [-1,1][+!!reverse];
}
The way I understand it, the purpose is to pick the proper index from the [-1,1]
array to then use it in the multiplication but it seems to me that [-1,1][+!!reverse];
could be safely replaced by [-1,1][+reverse];
Am I wrong? What do you gain or prevent by double-negating reverse
there?
I saw the above code on this answer.