median
Sorts a non-empty array by numeric value and returns the middle value.
API Reference
Signature
Parameters
Returns
Returns the middle value for odd-length arrays, or the mean of the two middle values for even-length arrays.
Throws
- Throws if
valuesis not a non-empty array. - Throws if any value is
NaN,Infinity, or-Infinity.
Agent Contract
Agent Notes
- Do not mutate the caller's array while sorting.
- Use
medianfor robust central tendency where outliers may exist.