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

111
Vistas
what's wrong with below recursive function?

its not returning anything, but return true or false are getting executed fine. Whenever array contains all odd number it should reach return true as array will be empty and return false if array element is not a odd number.

function isOdd(a) {
  return a % 2 == 1 ? true : false
}

function someRecursive(ary, isOdd) {
  if(ary.length == 0){
      return true;
  } 
  if(isOdd(ary[0])){
      someRecursive(ary.slice(1), isOdd);
  }else{
      return false;
  }  
}

someRecursive([1,3, 5], isOdd);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are not returning anything inside if condition. Return the value returned by the recursive function.

Some thing like this :

if(isOdd(ary[0])){
      
      return someRecursive(ary.slice(1), isOdd);
  }

function isOdd(a) {
  return a % 2 == 1 ? true : false
}

function someRecursive(ary, isOdd) {
  if(ary.length == 0){
      return true;
  } 
  if(isOdd(ary[0])){
      
      return someRecursive(ary.slice(1), isOdd);
  }else{
      return false;
  }  
}

console.log(someRecursive([1,3, 5], isOdd))

about 4 years ago · Juan Pablo Isaza Denunciar
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