Day 7 is counting the sum of vowels and consonant in a single string. A vowel will value of 1 and consonant will give value of 2.
For example, abcde
will give value of 8.
a=1, b=2, c=2, d=2, e=1
so 1+2+2+2+1
is 8.
This is the JavaScript solution
function countVowelConsonant(str) {
let strArray = str.split('');
let vowels = ['a','i','u','e','o'];
let result = strArray.reduce((total, letter) => {
return vowels.includes(letter) ? total + 1 : total + 2;
}, 0);
return result;
}
Top comments (0)