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

Function leastIndex

src/leastIndex.js:4–19  ·  view source on GitHub ↗
(values, compare = ascending)

Source from the content-addressed store, hash-verified

2import minIndex from "./minIndex.js";
3
4export default function leastIndex(values, compare = ascending) {
5 if (compare.length === 1) return minIndex(values, compare);
6 let minValue;
7 let min = -1;
8 let index = -1;
9 for (const value of values) {
10 ++index;
11 if (min < 0
12 ? compare(value, value) === 0
13 : compare(value, minValue) < 0) {
14 minValue = value;
15 min = index;
16 }
17 }
18 return min;
19}

Callers 2

leastIndex-test.jsFile · 0.90
scanFunction · 0.85

Calls 1

minIndexFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…