Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let winnerName;
- let winnerScore = 0;
- let name;
- while ((name = input.shift()) !== 'Stop') {
- let playerScore = 0;
- for (let i = 0; i < name.length; i++) {
- let number = Number(input.shift());
- let charCode = name.charCodeAt(i);
- if (number === charCode) {
- playerScore += 10;
- } else {
- playerScore += 2;
- }
- }
- if (playerScore >= winnerScore) {
- winnerName = name;
- winnerScore = playerScore;
- }
- }
- console.log(`The winner is ${winnerName} with ${winnerScore} points!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement