Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let powerfulSum = 0;
- let powerfulWord = '';
- let word;
- while ((word = input.shift()) !== 'End of words') {
- let currentWordPower = Array.from(word)
- .map(str => str.charCodeAt(0))
- .reduce((acc, cur) => acc + cur);
- if (word.match(/^[AEIOUY].*/i)) {
- currentWordPower *= word.length;
- } else {
- currentWordPower /= 2;
- }
- if (powerfulSum < currentWordPower) {
- powerfulSum = currentWordPower;
- powerfulWord = word;
- }
- }
- console.log(`The most powerful word is ${powerfulWord} - ${powerfulSum.toFixed(0)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement