Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Why is this recursive function not updating the count variable here?

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;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!