Function: compareBy()
compareBy<
ElementType>(iterable:IterableResolvable<undefined|ElementType>,other:IterableResolvable<undefined|ElementType>,comparator:CompareByComparator<ElementType>):LexicographicComparison
Defined in: projects/utilities/packages/iterator-utilities/src/lib/compareBy.ts:30
Lexicographically compares the elements of both iterators are equal. That is:
Type Parameters
| Type Parameter | 
|---|
| ElementType | 
Parameters
| Parameter | Type | Description | 
|---|---|---|
| iterable | IterableResolvable<undefined|ElementType> | The iterator to compare. | 
| other | IterableResolvable<undefined|ElementType> | The iterator to compare against. | 
| comparator | CompareByComparator<ElementType> | - | 
Returns
Whether the two iterators are equal.
Example
import { ascNumber, compareBy } from '@sapphire/iterator-utilities';
const x = [1, 2, 3, 4];
const y = [1, 4, 9, 16];
console.log(compareBy(x, y, (x, y) => ascNumber(x, y)));
// Output: -1
console.log(compareBy(x, y, (x, y) => ascNumber(x * x, y)));
// Output: 0
console.log(compareBy(x, y, (x, y) => ascNumber(x * 2, y)));
// Output: 1
Remarks
This function consumes the entire iterator.