Advertisement
Spocoman

Easter Competition

Feb 15th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterCompetition(input) {
  2.     let baker_num = Number(input.shift());
  3.     let bakerWin = "";
  4.     let maxPoint = 0;
  5.  
  6.     for (let i = 0; i < baker_num; i++) {
  7.         let baker = input.shift();
  8.         let points = 0;
  9.  
  10.         while (true) {
  11.             let info = input.shift();
  12.             if (info === "Stop") {
  13.                 break;
  14.             }
  15.             points += Number(info);
  16.         }
  17.  
  18.         if (maxPoint < points) {
  19.             maxPoint = points;
  20.             bakerWin = baker;
  21.             console.log(`${bakerWin} has ${maxPoint} points.`);
  22.             console.log(`${bakerWin} is the new number 1!`);
  23.         } else {
  24.             console.log(`${baker} has ${points} points.`);
  25.         }
  26.     }
  27.     console.log(`${bakerWin} won competition with ${maxPoint} points!`);
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement