Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- input = input.filter(x => x !== "END")
- let goals = []
- let bestPlayer = []
- let arrayLength = Math.floor(input.length / 2) //here
- for (let i = 0; i < arrayLength; i++) { //here
- 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.`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment