I encountered an issue with the comparison process. The expected result should be 11 since the cost of the product at index 11 is lower than the cost of the product at index 18. However, the computed result turns out to be 18.
var scores = [60, 50, 60, 58, 54, 54, 58, 50, 52, 54, 48, 69, 34, 55, 51, 52, 44, 51, 69, 64, 66, 55, 52, 61, 46, 31, 57, 52, 44, 18,
41, 53, 55, 61, 51, 44];
var costs = [.25, .27, .25, .25, .25, .25, .33, .31, .25, .29, .27, .22, .31, .25, .25, .33, .21, .25, .25, .25, .28, .25, .24, .22, .20, .25, .30, .25, .24, .25,
.25, .25, .27, .25, .26, .29];
//TOTAL, HIGHEST, INDEX OF THE HIGHEST
function findMaxIndex(array,arrayCost){
var maximum=Math.max(...array);
var arrayIndex=[];
for(var i=0;i<array.length;i++){
if(array[i]==maximum){
arrayIndex.push(i)
}
}
var minimum=arrayCost[arrayIndex[0]];//0.22
for(var i=0;i<arrayIndex.length;i++){
if(arrayCost[arrayIndex[i]]<=minimum){//0.25>=0.22
minimum=arrayIndex[i];
}
}
return minimum;
}