SHARE
TWEET

The Most Powerful Word

a guest Mar 26th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function word(input) {
  2.     let word = input.shift();
  3.  
  4.     let thePowerfulWord = "";
  5.     let powerOfTheWord = 0;
  6.  
  7.     while (word !== "End of words") {
  8.         let digitsSum = 0;
  9.         let index = 1;
  10.         let mustRound = false;
  11.        
  12.         for (let i = 0; i < word.length; i++) {
  13.             let currentDigit = Number(word.charCodeAt(i))
  14.             digitsSum += currentDigit;
  15.            
  16.             let firstDigit = word[0];
  17.             if (firstDigit === 'a' || firstDigit === 'e' || firstDigit === 'i' ||
  18.                 firstDigit === 'o' || firstDigit === 'u' || firstDigit === 'y' ||
  19.                 firstDigit === 'A' || firstDigit === 'E' || firstDigit === 'I' ||
  20.                 firstDigit === 'O' || firstDigit === 'U' || firstDigit === 'Y') {
  21.                 index = word.length;
  22.             }
  23.             else {
  24.                 index = 1 / word.length;
  25.                 mustRound = true;
  26.             }
  27.         }
  28.         let power = digitsSum * index;
  29.         if (power > powerOfTheWord) {
  30.             thePowerfulWord = word;
  31.             if (mustRound) {
  32.                 powerOfTheWord = Math.floor(power);
  33.             }
  34.             else {
  35.                 powerOfTheWord = Math.floor(power);
  36.             }
  37.         }
  38.         word = input.shift();
  39.     }
  40.     console.log(`The most powerful word is ${thePowerfulWord} - ${powerOfTheWord}`);
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top