source: node_modules/es-toolkit/dist/compat/math/meanBy.d.ts@ ba17441

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

Added visualizations

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[a762898]1import { ValueIteratee } from '../_internal/ValueIteratee.js';
2
3/**
4 * Calculates the average of an array of numbers when applying
5 * the `iteratee` function to each element.
6 *
7 * If the array is empty, this function returns `NaN`.
8 *
9 * @template T - The type of elements in the array.
10 * @param {T[]} items An array to calculate the average.
11 * @param {((element: T) => unknown) | PropertyKey | [PropertyKey, any] | PartialShallow<T>} iteratee
12 * The criteria used to determine the maximum value.
13 * - If a **function** is provided, it extracts a numeric value from each element.
14 * - If a **string** is provided, it is treated as a key to extract values from the objects.
15 * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
16 * - If an **object** is provided, it matches elements that contain the specified properties.
17 * @returns {number} The average of all the numbers as determined by the `iteratee` function.
18 *
19 * @example
20 * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
21 * meanBy([], x => x.a); // Returns: NaN
22 * meanBy([[2], [3], [1]], 0); // Returns: 2
23 * meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
24 */
25declare function meanBy<T>(items: ArrayLike<T> | null | undefined, iteratee?: ValueIteratee<T>): number;
26
27export { meanBy };
Note: See TracBrowser for help on using the repository browser.