-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathSplitStringByNumbers.js
More file actions
22 lines (20 loc) · 739 Bytes
/
SplitStringByNumbers.js
File metadata and controls
22 lines (20 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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++) {
let pontuacao = parseInt(pontuacoes[i]);
if (pontuacao > maiorPontuacao) {
maiorPontuacao = pontuacao;
qtdQuebraDeRecords++;
} else if (pontuacao < menorPontuacao) {
menorPontuacao = pontuacao;
piorJogo = i + 1;
}
}
return [qtdQuebraDeRecords, piorJogo];
}
console.log(avaliaPontuacoes("10, 20, 4, 8, 9, 22, 12, 43, 22"));
//https://pt.stackoverflow.com/q/505750/101