Function: isSortedBy()
isSortedBy<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,comparator
:CompareByComparator
<ElementType
>):boolean
Checks if the elements of this iterator are sorted using the given comparator function.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | The iterator to compare. |
comparator | CompareByComparator <ElementType > | - |
Returns
boolean
Seealso
isSorted for a version that uses the default comparator.
Seealso
isSortedByKey for a version that allows custom key extractors.
Example
import { ascNumber, isSortedBy } from '@sapphire/iterator-utilities';
assert(isSortedBy([1, 2, 2, 9], ascNumber));
assert(!isSortedBy([1, 2, 2, 9], ascNumber));
assert(isSortedBy([0], () => true));
assert(isSortedBy([0], () => false));
assert(isSortedBy([], () => true));
assert(isSortedBy([], () => false));
Remarks
This function consumes the entire iterator.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/isSortedBy.ts:34