source: node_modules/es-toolkit/dist/math/medianBy.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.0 KB
Line 
1/**
2 * Calculates the median of an array of elements when applying
3 * the `getValue` function to each element.
4 *
5 * The median is the middle value of a sorted array.
6 * If the array has an odd number of elements, the median is the middle value.
7 * If the array has an even number of elements, it returns the average of the two middle values.
8 *
9 * If the array is empty, this function returns `NaN`.
10 *
11 * @template T - The type of elements in the array.
12 * @param {T[]} items An array to calculate the median.
13 * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
14 * @returns {number} The median of all the numbers as determined by the `getValue` function.
15 *
16 * @example
17 * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
18 * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
19 * medianBy([], x => x.a); // Returns: NaN
20 */
21declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
22
23export { medianBy };
Note: See TracBrowser for help on using the repository browser.