So I needed to write a function that takes a string and returns a javascript object with vowels and consonants properties that maps to the number of vowels and consonants in the string
function getCount(words) {
let answer = {vowels: 0, consonants: 0};
if( typeof words !== 'string') { return answer }
let vowel = 'aeiouAEIOU'
for(char of words){
if(char === ' ') { continue }
if(vowel.indexOf(char) === -1){ // not a vowel
answer.consonants += 1
}
else if(vowel.indexOf(char) !== -1){ // is a vowel
answer.vowels += 1
}
}
return answer
}
Is there a better way of going about it? Preferably a functional approach