Comparators
Functions for comparing two elements of arbitrary types.
Import alias 'ads-js/comparators'
All comparators must implement the following common function interface:
/**
* Compares elements a and b.
*
* @template T Type of compared elements.
* @template K Optional type for element b used if comparator does support type conversion.
* @param a Compared element.
* @param b Compared element.
* @returns Result of comparison (1 if a is greater than b, -1 if a is less than b, 0 if they are equal).
*/
export interface IComparator<T, K = T> {
(a: T, b: K): ComparisonResult;
}You also can use your own functions or standard JavaScript collators as comparators.
compareAsStrings()
/**
* Compares the two elements a and b as Unicode strings. Both elements are allowed to be of any type.
* Type conversion is done implicitly by the comparator.
*
* @param a Compared element.
* @param b Compared element.
* @returns Result of comparison (1 if a is greater than b, -1 if a is less than b, 0 if they are equal).
*/
function compareAsStrings<T, K>(a: T, b: K): ComparisonResultcompareAsNumbers()
Last updated