source: node_modules/es-toolkit/dist/compat/math/maxBy.d.mts

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.mjs';
2
3/**
4 * Finds the element in an array that has the maximum value when applying
5 * the `iteratee` to each element.
6 *
7 * @template T - The type of elements in the array.
8 * @param {ArrayLike<T> | null | undefined} items The array of elements to search.
9 * @param {ValueIteratee<T>} iteratee
10 * The criteria used to determine the maximum 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 maximum value as determined by the `iteratee`.
16 * @example
17 * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
18 * maxBy([], x => x.a); // Returns: undefined
19 * maxBy(
20 * [
21 * { name: 'john', age: 30 },
22 * { name: 'jane', age: 28 },
23 * { name: 'joe', age: 26 },
24 * ],
25 * x => x.age
26 * ); // Returns: { name: 'john', age: 30 }
27 * maxBy([{ a: 1 }, { a: 2 }], 'a'); // Returns: { a: 2 }
28 * maxBy([{ a: 1 }, { a: 2 }], ['a', 1]); // Returns: { a: 1 }
29 * maxBy([{ a: 1 }, { a: 2 }], { a: 1 }); // Returns: { a: 1 }
30 */
31declare function maxBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): T | undefined;
32
33export { maxBy };
Note: See TracBrowser for help on using the repository browser.