Type Alias: Comparator()<T>
Comparator<
T> = (a,b) =>number
Defined in: compare/types.ts:17
A comparator function for sorting values of type T.
Returns:
- Negative number if a should come before b
- Zero if a and b are equal
- Positive number if a should come after b
Type Parameters
T
T
The type of values being compared
Parameters
a
T
b
T
Returns
number
Example
const numericComparator: Comparator<number> = (a, b) => a - b
[3, 1, 2].sort(numericComparator) // => [1, 2, 3]