georgiev955

Untitled

Feb 12th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function solve(input) {
  2. let strongestWord;
  3. let strongestWordScore = 0;
  4.  
  5. let word;
  6. while ((word = input.shift()) !== 'End of words') {
  7. let wordScore = 0;
  8. for (let i = 0; i < word.length; i++) {
  9. let letterScore = word.charCodeAt(i);
  10. wordScore+=letterScore;
  11. }
  12.  
  13. if ((word[0] === 'a'
  14. || word[0] === 'e'
  15. || word[0] === 'i'
  16. || word[0] === 'o'
  17. || word[0] === 'u'
  18. || word[0] === 'y') ||
  19. (word[0] === 'A'
  20. || word[0] === 'E'
  21. || word[0] === 'I'
  22. || word[0] === 'O'
  23. || word[0] === 'U'
  24. || word[0] === 'Y')) {
  25. wordScore*=word.length;
  26. } else {
  27. wordScore = Math.trunc(wordScore / word.length);
  28. }
  29.  
  30. if (wordScore >= strongestWordScore) {
  31. strongestWord = word;
  32. strongestWordScore = wordScore;
  33. }
  34. }
  35. console.log(`The most powerful word is ${strongestWord} - ${strongestWordScore}`);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment