Here is an array for reference:
var exampleArray = [10, 67, 100, 100];
The goal is to identify the indexes of the maximum values in the array.
The existing function currently locates only one index:
function findMaxIndexes(arr) {
var max = arr[0];
var maxIndexes = [0];
for (var i = 1; i < arr.length; i++) {
if (arr[i] > max) {
maxIndexes = [i];
max = arr[i];
} else if (arr[i] === max) {
maxIndexes.push(i);
}
}
return maxIndexes;
}
To update the function to return an array of max indexes, modify it as follows:
When used with the example array provided earlier, the modified function should return:
[2, 3]
.