source: node_modules/es-toolkit/dist/compat/math/minBy.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import { ValueIteratee } from '../_internal/ValueIteratee.js';
2
3/**
4 * Finds the element in an array that has the minimum value when applying
5 * the `iteratee` to each element.
6 *
7 * @template T - The type of elements in the array.
8 * @param {T[]} items The array of elements to search.
9 * @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
10 * The criteria used to determine the minimum value.
11 * - If a **function** is provided, it extracts a numeric value from each element.
12 * - If a **string** is provided, it is treated as a key to extract values from the objects.
13 * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
14 * - If an **object** is provided, it matches elements that contain the specified properties.
15 * @returns {T | undefined} The element with the minimum value as determined by the `iteratee`.
16 * @example
17 * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
18 * minBy([], x => x.a); // Returns: undefined
19 * minBy(
20 * [
21 * { name: 'john', age: 30 },
22 * { name: 'jane', age: 28 },
23 * { name: 'joe', age: 26 },
24 * ],
25 * x => x.age
26 * ); // Returns: { name: 'joe', age: 26 }
27 * minBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 1 }
28 * minBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 2 }
29 * minBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 2 }
30 */
31declare function minBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
32
33export { minBy };
Note: See TracBrowser for help on using the repository browser.