Type of elements within the source iterable.
The source iterable to inspect.
Percentile expressed as a fraction between 0 and 1 where 0 corresponds to the minimum and 1 to the maximum.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element. Defaults to treating the element itself as numeric.
Optionalstrategy: PercentileStrategyStrategy that determines how fractional ranks are resolved. Defaults to "linear", which interpolates between neighbouring values. Alternative strategies include "nearest", "low", "high", and "midpoint".
The percentile value, or NaN when source contains no elements.
source is enumerated once and buffered so the selection algorithm can determine the requested rank without fully sorting the data. When percent is outside [0, 1], the result is clamped to the range implied by strategy.
const upperQuartile = percentile([1, 2, 3, 4, 5], 0.75);
console.log(upperQuartile); // 4
const responseTimes = [
{ endpoint: '/users', duration: 120 },
{ endpoint: '/users', duration: 80 },
{ endpoint: '/users', duration: 200 }
];
const p95 = percentile(responseTimes, 0.95, r => r.duration, "nearest");
console.log(p95); // 200
Calculates a percentile of the numeric values produced by source.