|
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:
470 bytes
|
| Line | |
|---|
| 1 | import ascending from "./ascending.js";
|
|---|
| 2 | import maxIndex from "./maxIndex.js";
|
|---|
| 3 |
|
|---|
| 4 | export 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 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.