Function: minByKey()
minByKey<
ElementType,MappedType>(iterable:IterableResolvable<ElementType>,callbackFn: (element:ElementType,index:number) =>MappedType,comparator:CompareByComparator<MappedType>):null|ElementType
Defined in: projects/utilities/packages/iterator-utilities/src/lib/minByKey.ts:34
Returns the element that gives the minimum value from the specified 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 | 
| MappedType | 
Parameters
| Parameter | Type | Default value | Description | 
|---|---|---|---|
| iterable | IterableResolvable<ElementType> | undefined | An iterator of number values to determine the minimum value of. | 
| callbackFn | ( element:ElementType,index:number) =>MappedType | undefined | A function to execute for each element produced by the iterator. It should return a number value. | 
| comparator | CompareByComparator<MappedType> | defaultCompare | - | 
Returns
null | ElementType
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
minBy for a version that allows custom comparators.
Example
import { minByKey } from '@sapphire/iterator-utilities';
const iterable = [-3, 0, 1, 5, -10];
console.log(minByKey(iterable, (value) => Math.abs(value)));
// Output: 0
Remarks
This function consumes the entire iterator.