Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theMostPowerfulWord(input) {
- let index = 0;
- let command = input[index];
- index++;
- let maxWord = Number.MIN_SAFE_INTEGER;
- let maxWordName = "";
- while (command !== "End of words") {
- let asciiSum = 0;
- let firstLetterIsVocal = false;
- for (let i = 0; i < command.length; i++) {
- let asciiValue = command.charCodeAt(i);
- let vocals = ["a", "e", "i", "o", "u", "y", "A", "E", "I", "O", "U", "Y"];
- for (letter = 0; letter < vocals.length; letter++) {
- let currentLetter = vocals[letter];
- let firstLetter = command[0];
- if (firstLetter === currentLetter) {
- firstLetterIsVocal = true;
- break;
- }
- }
- asciiSum += asciiValue;
- }
- if (firstLetterIsVocal) {
- asciiSum *= command.length;
- } else {
- asciiSum = Math.floor (asciiSum / command.length);
- }
- if (asciiSum > maxWord) {
- maxWord = asciiSum;
- maxWordName = command;
- }
- command = input[index];
- index++;
- }
- console.log(`The most powerful word is ${maxWordName} - ${maxWord}`);
- }
- theMostPowerfulWord(["The", "Most", "Powerful", "Word", "Is", "Experience", "End of words"]);
- theMostPowerfulWord(["But", "Some", "People", "Say", "It's", "LOVE", "End of words"]);
Add Comment
Please, Sign In to add comment