Function: compare()
compare<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,other
:IterableResolvable
<ElementType
>):LexicographicComparison
Lexicographically compares the elements of both iterators are equal.
This function uses the default comparator (lexicographically), which means it will compare the elements as strings. If this is undesirable, use compareBy instead.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | The iterator to compare. |
other | IterableResolvable <ElementType > | The iterator to compare against. |
Returns
Whether the two iterators are equal.
Example
import { compare } from '@sapphire/iterator-utilities';
console.log(compare([1], [1]));
// Output: 0
console.log(compare([1], [1, 2]));
// Output: -1
console.log(compare([1, 2], [1]));
// Output: 1
Remarks
This function consumes the entire iterator.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/compare.ts:32