median (for BigInts) es-toolkit
Returns the middle value of an array of BigInts.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
median(nums)
Use median when you want the middle value of a set of BigInts. It sorts a copy of the array — your array is left untouched — and returns the value in the middle.
When the array has an even number of elements, the two middle values are averaged. BigInt has no fractional part, so that average is truncated toward zero.
There is no BigInt that means "no median" — BigInt has no NaN — so an empty array throws instead of returning a placeholder.
Parameters
The array of BigInts to calculate the median of.
Returns
Returns the median of the array. 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.