-3
The program I want to create should return an array with the number of records reached from a list of scores and the number of the position of the lowest score, respectively. However, it returns something different.
let stringPontuacoes = "10, 20, 4, 8, 9, 22, 12, 43, 22"
function avaliaPontuacoes (stringPontuacoes) {
let pontuacoes = stringPontuacoes.split(", ")
let qtdQuebraDeRecords = 0
let piorJogo = 1
let maiorPontuacao = pontuacoes[0]
let menorPontuacao = pontuacoes[0]
for (let i = 1; i < pontuacoes.length; i++) {
if(pontuacoes[i] > maiorPontuacao) {
maiorPontuacao = pontuacoes[i]
qtdQuebraDeRecords++
}else if (pontuacoes[i] < menorPontuacao) {
menorPontuacao = pontuacoes[i]
piorJogo = i+1;
}
}
return [qtdQuebraDeRecords, piorJogo]
}
console.log(avaliaPontuacoes(stringPontuacoes))
The code returns "[ 4, 1 ]", instead of "[ 3, 3 ]". I would really like your help in figuring out how to solve this problem.