Advertisement
Guest User

Untitled

a guest
May 21st, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let winnerName;
  3.   let winnerScore = 0;
  4.  
  5.   let name;
  6.   while ((name = input.shift()) !== 'Stop') {
  7.     let playerScore = 0;
  8.  
  9.     for (let i = 0; i < name.length; i++) {
  10.       let number = Number(input.shift());
  11.       let charCode = name.charCodeAt(i);
  12.  
  13.       if (number === charCode) {
  14.         playerScore += 10;
  15.       } else {
  16.         playerScore += 2;
  17.       }
  18.     }
  19.  
  20.     if (playerScore >= winnerScore) {
  21.       winnerName = name;
  22.       winnerScore = playerScore;
  23.     }
  24.   }
  25.  
  26.   console.log(`The winner is ${winnerName} with ${winnerScore} points!`);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement