just-percentile
v4.2.0
Published
return the value at the given percentile (using linear interpolation)
Downloads
2,898
Maintainers
Readme
just-percentile
Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.
npm install just-percentile
yarn add just-percentile
Return the value at the given percentile (using linear interpolation)
import percentile from 'just-percentile';
percentile([1, 2, 3], 0); // 1
percentile([1, 2, 3], 0.5); // 2
percentile([1, 2, 3], 1); // 3
// See https://en.wikipedia.org/wiki/Percentile (linear interpolation method)
percentile([15, 20, 35, 40, 50], 0.05); // 15
percentile([15, 20, 35, 40, 50], 0.3); // 20
percentile([15, 20, 35, 40, 50], 0.4); // 27.5
percentile([15, 20, 35, 40, 50], 0.95); // 50
percentile(1, 2, 3, 50); // throws
percentile(['1', 2, 3], 50); // throws
percentile([], 50); // throws