Advertisement
Alexzandur

06.The Most Powerful World

Jul 11th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let name = input.shift();
  3.  
  4.     let winnerName = '';
  5.     let winnerScore = 0;
  6.  
  7.     while (name != 'End of words') {
  8.         let sum = 0;
  9.         for (i = 0; i < name.length; i++) {
  10.             sum += name.charCodeAt(i);
  11.         }
  12.             if (i == 0 || name.charCodeAt(0) == 97 || name.charCodeAt(0) == 101 || name.charCodeAt(0) == 105
  13.                 || name.charCodeAt(0) == 111 || name.charCodeAt(0) == 117 || name.charCodeAt(0) == 121) {
  14.                 sum *= name.length;
  15.             } else if (i == 0 || name.charCodeAt(0) == 65 || name.charCodeAt(0) == 69 || name.charCodeAt(0) == 73
  16.                 || name.charCodeAt(0) == 97 || name.charCodeAt(0) == 85 || name.charCodeAt(0) == 89) {
  17.                 sum *= name.length;
  18.             } else {
  19.                 sum /= name.length;
  20.             }
  21.        
  22.         if (winnerScore < sum) {
  23.             winnerScore = sum;
  24.             winnerName = name;
  25.         }
  26.         name = input.shift();
  27.  
  28.     }
  29.     console.log(`The most powerful word is ${winnerName} - ${winnerScore}`)
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement