I am programming a recursive function that counts the total number of vowels in a given string. The helper function seems to work, as it identifies the vowels correctly. However, I keep getting 0 as return value no matter what string argument I give. Could anyone advise me what I'm not seeing here is?
const countVowels = (aStr) => {
let numVowel = 0;
if (aStr.length === 0) return 0;
if (isAVowel(aStr[0])) numVowel += 1;
countVowels(aStr.slice(1));
return numVowel;
}
// helper function
const isAVowel = (char) => {
vowels = ["a", "e", "i", "o", "u"];
if (vowels.includes(char.toLowerCase())) return true;
}