3 ms·
That will give you a sequence of decreasing numbers. `a-b` will work just as `a > b`. If `a-b` returns a negative number, the result will be treated as -1. If
by 52-6F-62 8y ago
That will give you a sequence of decreasing numbers. `a-b` will work just as `a > b`.
If `a-b` returns a negative number, the result will be treated as -1. If the numbers are the same, then you end up with 0, and so on.
I don't know what's faster in that case.
- jwilk 8y agoa > b is not a consistent comparison function. The behavior of sort() with such a function is implementation-defined.
- 52-6F-62 8y agoAgreed. I wouldn't use it the way shown here. I would make sure to return a hard negative, zero, or one in any case. I was surprised when I read into how many different ways `Array.prototype.sort()` is implemented across environments.