percentile (for BigInts) es-toolkit
Returns the BigInt at a given percentile of an array.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
percentile(arr, percentile)
Use percentile when you want to know the value below which a given share of your data falls — a p90 latency, for example. It sorts a copy of the array — your array is left untouched — and picks the value at the matching rank.
This uses the nearest-rank method, so the answer is always a value that is already in the array. It never interpolates between two values, which means it never has to round.
The percentile itself is an ordinary number between 0 and 100, not a BigInt, because it is a percentage rather than a quantity being measured.
Parameters
The array of BigInts to calculate the percentile of.
The percentile to look up, between 0 and 100.
Returns
Returns the BigInt at the given percentile. Always one of the values already in the array.
Throws
Throws an error if percentile is NaN, less than 0, or greater than 100. 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.