Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let countKozunaks = Number(input[0]);
- let score = 0;
- let index = 1;
- let winnerChef = 0;
- let winnersScore = 0;
- let nameOfChef = '';
- for (let i = 1; i <= countKozunaks; i++) {
- nameOfChef = input[index];
- index++;
- while (input[index] !== 'Stop') {
- let current = Number(input[index]);
- score += current;
- index++;
- } // while
- if (winnersScore < score) {
- winnerChef = nameOfChef;
- winnersScore = score;
- console.log(`${winnerChef} has ${winnersScore} points.`);
- console.log(`${winnerChef} is the new number 1!`);
- } else {
- console.log(`${nameOfChef} has ${score} points.`);
- }
- nameOfChef = '';
- score = 0;
- index++;
- } // for
- console.log(`${winnerChef} won competition with ${winnersScore} points!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement