median es-toolkit
Calculates the median of an array of numbers.
Usage
median(nums)
Use median when you want to find the median value of an array of numbers. After sorting the array in ascending order, it finds the value located in the middle. For an array with an odd number of elements, it returns the exact middle value, and for an array with an even number of elements, it returns the average of the two middle values. If given an empty array, it returns NaN.
Parameters
An array of numbers to calculate the median.
Returns
Returns the median of all numbers in the array. Returns NaN 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.