// Using Reduce
function countVowelConsonant(str) {
const arr = str.split('');
const vowels = ["a", "e", "i", "o", "u"];
return arr.reduce((sum, currentVal) => vowels.includes(currentVal) ? ++sum : sum += 2, 0);
}
// Using Regular Expression
// function countVowelConsonant(str) {
// const vowels = str.match(/[aeiou]/gi).length;
// const consonants = str.length - vowels;
// return vowels + consonants * 2;
// }
/**
* 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);
});
});