I'm trying to create a function that compare 2 arrays and decide a winner who won more rounds. Each item of the array represents the points each player made in their respective rounds. So the winner of the round is who made more points.
for example:
player1= [4,5,7,8] player2= [5,3,2,1]
the result should be player1 because he won more rounds (5>3, 7>2 8>1).
function solution(result1,result2) {
let player1 = 0
let player2 = 0
for(let i=0; i<result1.length; i++){
if (result1[i] > result2[i]){
player1++
}else if(result2[i]>result1[i]){
player2++
}else(result1[i] == result[i]);{
player1++
player2++
}if (player1 > player2){
console.log("PLAYER1")
}else if(player1 == player2){
console.log("TIE")
}else {
console.log("PLAYER2")
}
}
}```