Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gameOfnames(input) {
- let index = 0;
- let command = input[index];
- index++;
- let winner;
- let highestPoints = Number.MIN_SAFE_INTEGER;
- while (command !== "Stop") {
- let totalPoints = 0;
- for (let i = 0; i < command.length; i++) {
- let currentNumber = Number(input[index]);
- index++;
- let letter = command[i];
- let asciiLetter = String.fromCharCode(currentNumber);
- if (asciiLetter === letter) {
- totalPoints += 10;
- } else {
- totalPoints += 2;
- }
- }
- if (totalPoints >= highestPoints) {
- highestPoints = totalPoints;
- winner = command;
- }
- command = input[index];
- index++;
- }
- console.log(`The winner is ${winner} with ${highestPoints} points!`);
- }
- gameOfnames (["Ivan", "73", "20", "98", "110", "Ivo", "80", "65", "87", "Stop"]);
- gameOfnames (["Pesho", "124", "34", "111", "97", "99", "Gosho", "98", "124", "88", "76", "18", "Stop"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement