(values, compare = ascending)
| 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 | } |
no test coverage detected
searching dependent graphs…