Advertisement
Guest User

Kozunaci

a guest
Jun 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let kozunakCount = Number(input.shift());
  3.  
  4.     let maxPoints = 0;
  5.     let winnerName = "";
  6.  
  7.     for (let currentKozunak = 0; currentKozunak < kozunakCount; currentKozunak++) {
  8.  
  9.         let chefName = input.shift();
  10.         let points = 0;
  11.  
  12.         while (true) {
  13.             let command = input.shift();
  14.             if (command === "Stop") {
  15.                 break;
  16.             }
  17.             points += Number(command);
  18.         }
  19.  
  20.         console.log(`${chefName} has ${points} points.`);
  21.  
  22.         if (maxPoints < points) {
  23.             maxPoints = points;
  24.             winnerName = chefName;
  25.             console.log(`${chefName} is the new number 1!`)
  26.         }
  27.  
  28.     }
  29.  
  30.  
  31.     console.log(`${winnerName} won competition with ${maxPoints} points!`)
  32.  
  33. }
  34.  
  35. solve([3, 'Chef Manchev', 10, 10, 10, 10, 'Stop', 'Natalie', 8, 2, 9, 'Stop', 'George', 9, 2, 4, 2, 'Stop'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement