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

178
Vistas
Why isn't my callback on the array working?

I wrote the code to iterate through a given array and then invoke the function subtractTwo on each element. However, when I run the function map the array argument returns unchanged. Does anyone know why this might be?

// create the subtractTwo function, callback function 
function subtractTwo (number) {
    return number - 2; 
}

// create higher-order function, map 
function map (array, callback) {
  // initiate a for loop, looping through the array and invoking the callback on each element; 
  for (let i = 0; i < array.length; i ++) { 
    callback(array[i]);
    
  }
  //return the new array
  return array;
}


//console.log(subtractTwo(4));
// Uncomment these to check your work!
console.log(typeof subtractTwo); // should log: 'function'
console.log(typeof map); // should log: 'function'
console.log(map([3,4,5], subtractTwo)); // should log: [ 1, 2, 3 ]```
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