Compares two elements of type T and returns a number indicating their relative order.
a
is less than b
, a negative number is returned.a
is greater than b
, a positive number is returned.a
is equal to b
, 0 is returned.A negative, positive, or zero value indicating the comparison result.
const comparator: Comparator<number> = { compare: (a, b) => a - b };
console.log(comparator.compare(3, 5)); // Output: -2
const stringComparator: Comparator<string> = { compare: (a, b) => a.localeCompare(b) };
console.log(stringComparator.compare("apple", "banana")); // Output: -1
Generated using TypeDoc
Represents a generic comparator function for comparing two elements of the same type.
Since
version 1.4.0
Author
Manuel Santos ney.br.santos@gmail.com