Function: minBy()
minBy<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,comparator
:CompareByComparator
<ElementType
>):ElementType
|null
Returns the element that gives the minimum value with respect to the specified comparison function.
If several elements are equally minimum, the last element is returned. If the iterator is empty, null
is returned.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator of number values to determine the minimum value of. |
comparator | CompareByComparator <ElementType > | - |
Returns
ElementType
| null
The element that gives the minimum value from the specified function, or null
if the iterator is empty.
Seealso
min for a version that uses the default comparator.
Seealso
minByKey for a version that allows custom key extractors.
Example
import { ascNumber, minBy } from '@sapphire/iterator-utilities';
const iterable = [-3, 0, 1, 5, -10];
console.log(minBy(iterable, ascNumber));
// Output: -10
Remarks
This function consumes the entire iterator.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/minBy.ts:33