Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda