Reputation: 159
So I saw this code and have no clue what the *
in sortBy[i].direction*(...)
does. Can anyone break this down for me and help me understand this code?
result = sortBy[i].direction*(a[ sortBy[i].prop ] < b[ sortBy[i].prop ] ? -1 : (a[ sortBy[i].prop ] > b[ sortBy[i].prop ] ? 1 : 0));
Upvotes: 0
Views: 53
Reputation: 11496
The *
operator multiples the value of sortBy[i].direction
with
-1 if a[sortBy[i].prop] < b[sortBy[i].prop]
;
1 if a[sortBy[i].prop] > b[sortBy[i].prop]
;
0 otherwise.
Look at this as
result = sortBy[i].direction *
(a[sortBy[i].prop] < b[sortBy[i].prop]
? -1
: (a[sortBy[i].prop] > b[sortBy[i].prop]
? 1
: 0));
Upvotes: 5