medianBy (for BigInts) es-toolkit
Returns the middle of the BigInts that a function derives from each element of an array.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
medianBy(items, getValue)
Use medianBy when the BigInts you want the median of are inside objects. Pass a function that pulls the value out of each element, and it takes the median of everything that function returns.
Just like median, an even number of elements averages the two middle values and truncates toward zero, and an empty array throws.
Parameters
The array of elements to calculate the median of.
A function that returns the BigInt to use for each element.
Returns
Returns the median of every value returned by getValue. For an even number of elements, returns the average of the two middle values, truncated toward zero.
Throws
Throws a RangeError if the array is empty.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.