Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let strongestWord;
- let strongestWordScore = 0;
- let word;
- while ((word = input.shift()) !== 'End of words') {
- let wordScore = 0;
- for (let i = 0; i < word.length; i++) {
- let letterScore = word.charCodeAt(i);
- wordScore+=letterScore;
- }
- if ((word[0] === 'a'
- || word[0] === 'e'
- || word[0] === 'i'
- || word[0] === 'o'
- || word[0] === 'u'
- || word[0] === 'y') ||
- (word[0] === 'A'
- || word[0] === 'E'
- || word[0] === 'I'
- || word[0] === 'O'
- || word[0] === 'U'
- || word[0] === 'Y')) {
- wordScore*=word.length;
- } else {
- wordScore = Math.trunc(wordScore / word.length);
- }
- if (wordScore >= strongestWordScore) {
- strongestWord = word;
- strongestWordScore = wordScore;
- }
- }
- console.log(`The most powerful word is ${strongestWord} - ${strongestWordScore}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment