Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function word(input) {
- let word = input.shift();
- let thePowerfulWord = "";
- let powerOfTheWord = 0;
- while (word !== "End of words") {
- let digitsSum = 0;
- let index = 1;
- let mustRound = false;
- for (let i = 0; i < word.length; i++) {
- let currentDigit = Number(word.charCodeAt(i))
- digitsSum += currentDigit;
- let firstDigit = word[0];
- if (firstDigit === 'a' || firstDigit === 'e' || firstDigit === 'i' ||
- firstDigit === 'o' || firstDigit === 'u' || firstDigit === 'y' ||
- firstDigit === 'A' || firstDigit === 'E' || firstDigit === 'I' ||
- firstDigit === 'O' || firstDigit === 'U' || firstDigit === 'Y') {
- index = word.length;
- }
- else {
- index = 1 / word.length;
- mustRound = true;
- }
- }
- let power = digitsSum * index;
- if (power > powerOfTheWord) {
- thePowerfulWord = word;
- if (mustRound) {
- powerOfTheWord = Math.floor(power);
- }
- else {
- powerOfTheWord = Math.floor(power);
- }
- }
- word = input.shift();
- }
- console.log(`The most powerful word is ${thePowerfulWord} - ${powerOfTheWord}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement