source: node_modules/d3-array/src/greatest.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 675 bytes
Line 
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}
Note: See TracBrowser for help on using the repository browser.