Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theMostPowerfulWord(input) {
- let index = 0;
- let word = input[index];
- index++;
- let wordPower = 0;
- let theMostPowerful = "";
- let theBestPower = 0;
- while (word !== "End of words") {
- let wordValue = 0;
- let firstLetter = "";
- for (let i = 0; i < word.length; i++) {
- let letterValue = word.charCodeAt(i);
- wordValue += letterValue;
- }
- firstLetter = word.charAt(0);
- if (firstLetter === "a" || firstLetter === "e" || firstLetter === "i"
- || firstLetter === "o" || firstLetter === "u" || firstLetter === "y"
- || firstLetter === "A" || firstLetter === "E" || firstLetter === "I"
- || firstLetter === "O" || firstLetter === "U" || firstLetter === "Y") {
- wordPower = Math.floor(wordValue * word.length);
- } else {
- wordPower = Math.floor(wordValue / word.length);
- }
- if (wordPower >= theBestPower) {
- theMostPowerful = word;
- theBestPower = wordPower;
- }
- word = input[index];
- index++;
- }
- console.log(`The most powerful word is ${theMostPowerful} - ${theBestPower}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment