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

Function greatest

src/greatest.js:3–29  ·  view source on GitHub ↗
(values, compare = ascending)

Source from the content-addressed store, hash-verified

1import ascending from "./ascending.js";
2
3export default function greatest(values, compare = ascending) {
4 let max;
5 let defined = false;
6 if (compare.length === 1) {
7 let maxValue;
8 for (const element of values) {
9 const value = compare(element);
10 if (defined
11 ? ascending(value, maxValue) > 0
12 : ascending(value, value) === 0) {
13 max = element;
14 maxValue = value;
15 defined = true;
16 }
17 }
18 } else {
19 for (const value of values) {
20 if (defined
21 ? compare(value, max) > 0
22 : compare(value, value) === 0) {
23 max = value;
24 defined = true;
25 }
26 }
27 }
28 return max;
29}

Callers 2

greatest-test.jsFile · 0.85
quantileIndexFunction · 0.85

Calls 1

ascendingFunction · 0.85

Tested by

no test coverage detected