05. Best Player с масив
Здравейте, опитах се да реша тази задача с масив, но получавам 80/100
Някой може ли да ми помогне ?
Благодаря :)
задача: https://judge.softuni.org/Contests/Practice/Index/2507#4
код:
function solve(input) {
input = input.filter(x => x !== "END")
let goals = []
let bestPlayer = []
for(let i = 0; i < input.length; i ++){
let command = String(input.shift())
let currGoals = Number(input.shift())
bestPlayer[i] = command
goals[i] = currGoals
if(goals[i] >= 10){
break;
}
}
let mostGoals = goals.indexOf(Math.max(...goals))
if(goals[mostGoals] >= 3){
console.log(`${bestPlayer[mostGoals]} is the best player!`);
console.log(`He has scored ${goals[mostGoals]} goals and made a hat-trick !!!`);
} else {
console.log(`${bestPlayer[mostGoals]} is the best player!`);
console.log(`He has scored ${goals[mostGoals]} goals.`)
}
}
Благодаря :)