Guest User

Untitled

a guest
Jun 9th, 2023
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     input = input.filter(x => x !== "END")
  3.     let goals = []
  4.     let bestPlayer = []
  5.     let arrayLength = Math.floor(input.length / 2)      //here
  6.  
  7.     for (let i = 0; i < arrayLength; i++) {             //here
  8.         let command = String(input.shift())
  9.         let currGoals = Number(input.shift())
  10.         bestPlayer[i] = command
  11.         goals[i] = currGoals
  12.  
  13.         if (goals[i] >= 10) {
  14.             break;
  15.         }
  16.     }
  17.     let mostGoals = goals.indexOf(Math.max(...goals))
  18.     if (goals[mostGoals] >= 3) {
  19.         console.log(`${bestPlayer[mostGoals]} is the best player!`);
  20.         console.log(`He has scored ${goals[mostGoals]} goals and made a hat-trick !!!`);
  21.     } else {
  22.         console.log(`${bestPlayer[mostGoals]} is the best player!`);
  23.         console.log(`He has scored ${goals[mostGoals]} goals.`)
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment