scrimba
Note at 0:30
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:30
AboutCommentsNotes
Note at 0:30
Expand for more info
main.js
run
preview
console
// 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);
});
});
Console
"result: "
,
undefined
,
/index.html
LIVE