Comparator<T>: BiFunction<T, T, number>

Type of function that takes a value of type T and returns a number, denoting the order of the input value.

Type Parameters

  • T

    The type of the input to the function

Returns

  • Zero if the first input value is equal to the second input value
  • A negative number if the first input value is less than the second input value
  • A positive number if the first input value is greater than the second input value

Example

const compareNumbers: Comparator<number> = (a, b) => a - b; // ascending order
const compareStrings: Comparator<string> = (a, b) => a.localeCompare(b); // lexicographical order

Generated using TypeDoc