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

Function quantileIndex

src/quantile.js:35–47  ·  view source on GitHub ↗
(values, p, valueof = number)

Source from the content-addressed store, hash-verified

33}
34
35export function quantileIndex(values, p, valueof = number) {
36 if (isNaN(p = +p)) return;
37 numbers = Float64Array.from(values, (_, i) => number(valueof(values[i], i, values)));
38 if (p <= 0) return minIndex(numbers);
39 if (p >= 1) return maxIndex(numbers);
40 var numbers,
41 index = Uint32Array.from(values, (_, i) => i),
42 j = numbers.length - 1,
43 i = Math.floor(j * p);
44 quickselect(index, i, 0, j, (i, j) => ascendingDefined(numbers[i], numbers[j]));
45 i = greatest(index.subarray(0, i + 1), (i) => numbers[i]);
46 return i >= 0 ? i : -1;
47}

Callers 2

quantile-test.jsFile · 0.90
medianIndexFunction · 0.90

Calls 6

ascendingDefinedFunction · 0.90
numberFunction · 0.85
minIndexFunction · 0.85
maxIndexFunction · 0.85
quickselectFunction · 0.85
greatestFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…