Advertisement
Guest User

Untitled

a guest
May 21st, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let powerfulSum = 0;
  3.   let powerfulWord = '';
  4.  
  5.   let word;
  6.   while ((word = input.shift()) !== 'End of words') {
  7.     let currentWordPower = Array.from(word)
  8.       .map(str =>  str.charCodeAt(0))
  9.       .reduce((acc, cur) => acc + cur);
  10.  
  11.     if (word.match(/^[AEIOUY].*/i)) {
  12.       currentWordPower *= word.length;
  13.     } else {
  14.       currentWordPower /= 2;
  15.     }
  16.  
  17.     if (powerfulSum < currentWordPower) {
  18.       powerfulSum = currentWordPower;
  19.       powerfulWord = word;
  20.     }
  21.   }
  22.  
  23.   console.log(`The most powerful word is ${powerfulWord} - ${powerfulSum.toFixed(0)}`);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement