MCPcopy Create free account
hub / github.com/d3/d3-array / quantile

Function quantile

src/quantile.js:10–21  ·  view source on GitHub ↗
(values, p, valueof)

Source from the content-addressed store, hash-verified

8import greatest from "./greatest.js";
9
10export default function quantile(values, p, valueof) {
11 values = Float64Array.from(numbers(values, valueof));
12 if (!(n = values.length) || isNaN(p = +p)) return;
13 if (p <= 0 || n < 2) return min(values);
14 if (p >= 1) return max(values);
15 var n,
16 i = (n - 1) * p,
17 i0 = Math.floor(i),
18 value0 = max(quickselect(values, i0).subarray(0, i0 + 1)),
19 value1 = min(values.subarray(i0 + 1));
20 return value0 + (value1 - value0) * (i - i0);
21}
22
23export function quantileSorted(values, p, valueof = number) {
24 if (!(n = values.length) || isNaN(p = +p)) return;

Callers 3

quantile-test.jsFile · 0.90
medianFunction · 0.85

Calls 4

numbersFunction · 0.90
minFunction · 0.85
maxFunction · 0.85
quickselectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…