Examples
Write countVowels so that the following cases hold.
- Input
countVowels("javascript")Output3 - Input
countVowels("HELLO")Output2 - Input
countVowels("xyz")Output0
1 more hidden test cases - 4 in total will be graded.
Answer
js
function countVowels(str) {
return (str.match(/[aeiou]/gi) || []).length;
}
countVowels("javascript"); // 3
Without regex, loop over the characters and test "aeiou".includes(ch.toLowerCase()). Remember uppercase input and the empty string.
