UNPKG

932 BJavaScriptView Raw
1import { extremaBy } from './_extremaby';
2import { equalityComparer } from '../util/comparer';
3/**
4 * Returns the elements in an terable sequence with the minimum key value.
5 *
6 * @export
7 * @template TSource The type of the elements in the source sequence.
8 * @template TKey The type of the key computed for each element in the source sequence.
9 * @param {Iterable<TSource>} source An async-iterable sequence to get the minimum elements for.
10 * @param {ExtremaOptions<TSource, TKey>} [options] The options which include an optional comparer.
11 * @returns {TSource[]} A list of zero or more elements that have a minimum key value.
12 */
13export function minBy(source, options) {
14 const { ['comparer']: comparer = equalityComparer, ['selector']: selector } = options || {};
15 const newComparer = (key, minValue) => -comparer(key, minValue);
16 return extremaBy(source, selector, newComparer);
17}
18
19//# sourceMappingURL=minby.mjs.map