Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let name = input.shift();
- let winnerName = '';
- let winnerScore = 0;
- while (name != 'End of words') {
- let sum = 0;
- for (i = 0; i < name.length; i++) {
- sum += name.charCodeAt(i);
- }
- if (i == 0 || name.charCodeAt(0) == 97 || name.charCodeAt(0) == 101 || name.charCodeAt(0) == 105
- || name.charCodeAt(0) == 111 || name.charCodeAt(0) == 117 || name.charCodeAt(0) == 121) {
- sum *= name.length;
- } else if (i == 0 || name.charCodeAt(0) == 65 || name.charCodeAt(0) == 69 || name.charCodeAt(0) == 73
- || name.charCodeAt(0) == 97 || name.charCodeAt(0) == 85 || name.charCodeAt(0) == 89) {
- sum *= name.length;
- } else {
- sum /= name.length;
- }
- if (winnerScore < sum) {
- winnerScore = sum;
- winnerName = name;
- }
- name = input.shift();
- }
- console.log(`The most powerful word is ${winnerName} - ${winnerScore}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement