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

Function greatestIndex

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

maxIndexFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…