MCPcopy Create free account
hub / github.com/breck7/scroll / rank

Function rank

external/.d3.js:1101–1121  ·  view source on GitHub ↗
(values, valueof = ascending$3)

Source from the content-addressed store, hash-verified

1099}
1100
1101function rank(values, valueof = ascending$3) {
1102 if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
1103 let V = Array.from(values);
1104 const R = new Float64Array(V.length);
1105 if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
1106 const compareIndex = (i, j) => valueof(V[i], V[j]);
1107 let k, r;
1108 values = Uint32Array.from(V, (_, i) => i);
1109 // Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
1110 values.sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
1111 values.forEach((j, i) => {
1112 const c = compareIndex(j, k === undefined ? j : k);
1113 if (c >= 0) {
1114 if (k === undefined || c > 0) k = j, r = i;
1115 R[j] = r;
1116 } else {
1117 R[j] = NaN;
1118 }
1119 });
1120 return R;
1121}
1122
1123function least(values, compare = ascending$3) {
1124 let min;

Callers

nothing calls this directly

Calls 7

ascendingDefinedFunction · 0.85
compareDefinedFunction · 0.85
compareIndexFunction · 0.85
mapMethod · 0.80
sortMethod · 0.80
forEachMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected