ErolKZ

Untitled

Jul 15th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 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.  
  21. while (input[index] !== 'Stop') {
  22.  
  23.  
  24. if (isNaN(input[index])) {
  25.  
  26. nameOfChef = input[index];
  27.  
  28. index++;
  29.  
  30. }
  31.  
  32.  
  33.  
  34. let current = Number(input[index]);
  35.  
  36. score += current;
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. index++;
  44.  
  45. } // while
  46.  
  47.  
  48. if (winnersScore < score) {
  49.  
  50. winnerChef = nameOfChef;
  51.  
  52. winnersScore = score;
  53.  
  54. console.log(`${winnerChef} has ${winnersScore} points.`);
  55.  
  56. console.log(`${winnerChef} is the new number 1!`);
  57.  
  58. } else {
  59.  
  60. console.log(`${nameOfChef} has ${score} points.`);
  61.  
  62. }
  63.  
  64.  
  65. nameOfChef = '';
  66.  
  67. score = 0;
  68.  
  69. index++;
  70.  
  71. } // for
  72.  
  73.  
  74. console.log(`${winnerChef} won competition with ${winnersScore} points!`);
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment