Find the index of the maximum item of an array
const indexOfMax = arr => arr.reduce((prev, curr, i, a) => curr > a[prev] ? i : prev, 0);
// Examples
indexOfMax([1, 3, 9, 7, 5]); // 2
indexOfMax([1, 3, 7, 7, 5]); // 2
Find the index of the maximum item of an array
const indexOfMax = arr => arr.reduce((prev, curr, i, a) => curr > a[prev] ? i : prev, 0);
// Examples
indexOfMax([1, 3, 9, 7, 5]); // 2
indexOfMax([1, 3, 7, 7, 5]); // 2
For further actions, you may consider blocking this person and/or reporting abuse
Krishna Bhamare -
Mario Dias -
Paul Osadchuk -
antonmak1 -
Top comments (0)