Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda