Compares two objects of the same type.
A negative number if a
is less than b
,
zero if they are equal, or a positive number if a
is greater than b
.
const stringComparator: InlineComparator<string> = (a, b) => a.localeCompare(b);
const stringComparison = stringComparator("apple", "banana");
console.log(stringComparison); // Output: -1 (Example output; actual output will vary)
const numberComparator: InlineComparator<number> = (a, b) => a - b;
const numberComparison = numberComparator(10, 5);
console.log(numberComparison); // Output: 5 (Example output; actual output will vary)
const dateComparator: InlineComparator<Date> = (a, b) => a.getTime() - b.getTime();
const dateComparison = dateComparator(new Date("2023-01-01"), new Date("2023-01-15"));
console.log(dateComparison); // Output: -1209600000 (Example output; actual output will vary)
Generated using TypeDoc
Interface representing a comparator function that can be used to compare two objects.
Comparator
Since
version 1.4.0
Author
Manuel Santos ney.br.santos@gmail.com