Advertisement
ErolKZ

Untitled

Jul 15th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let countKozunaks = Number(input[0]);
  5.  
  6. let score = 0;
  7.  
  8. let index = 1;
  9.  
  10. let winnerChef = 0;
  11.  
  12. let winnersScore = 0;
  13.  
  14. let nameOfChef = '';
  15.  
  16.  
  17.  
  18. for (let i = 1; i <= countKozunaks; i++) {
  19.  
  20. nameOfChef = input[index];
  21.  
  22. index++;
  23.  
  24. while (input[index] !== 'Stop') {
  25.  
  26.  
  27. let current = Number(input[index]);
  28.  
  29. score += current;
  30.  
  31.  
  32.  
  33. index++;
  34.  
  35. } // while
  36.  
  37.  
  38. if (winnersScore < score) {
  39.  
  40. winnerChef = nameOfChef;
  41.  
  42. winnersScore = score;
  43.  
  44. console.log(`${winnerChef} has ${winnersScore} points.`);
  45.  
  46. console.log(`${winnerChef} is the new number 1!`);
  47.  
  48. } else {
  49.  
  50. console.log(`${nameOfChef} has ${score} points.`);
  51.  
  52. }
  53.  
  54.  
  55. nameOfChef = '';
  56.  
  57. score = 0;
  58.  
  59. index++;
  60.  
  61. } // for
  62.  
  63.  
  64. console.log(`${winnerChef} won competition with ${winnersScore} points!`);
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement