function countVowelConsonant(str) {
// write code here
//splitting the string and using the resulting value to reduce it
const count = str.split("").reduce( (accu , currentValue) => {
// using a siwtch statement since is much easier than a if else
// and with no break statement if it is a vowel it will fall trough and always add one
switch(currentValue){
case "a":
case "e":
case "i":
case "o":
case "u":
return accu + 1;
default:
// if it is any other that is not a vowel add 2
return accu + 2;
}
}, 0);
// return count
return count;
}
/**
* Test Suite
*/
describe('countVowelConsonant()', () => {
it('returns total of vowels(1) and consonants(2) to be added', () => {
// arrange
const value = 'abcde';
// act
const result = countVowelConsonant(value);
// log
console.log("result: ", result);
// assert
expect(result).toBe(8);
});
});