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

176
Vistas
Can I use an anonymous function with the .map() iterator in javascript?

I am trying to get this code to return a new array using .map(). For some reason I cannot figure out how to make the anonymous function work with it. Here is my code. It just returns undefined, smh.

const numbers = [2, 7, 9, 171, 52, 33, 14]

const toSquare = num => num * num

// Write your code here:
function squareNums(numArr) {
  numArr.map(num => {
    return (num ** 2);
  })
};

const numberArray = squareNums(numbers);
console.log(numberArray);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is correct, it's just your squareNums function doesn't return anything. In fact, that means it returns undefined, which is what you see printed in the console.

Return the result of numArr.map instead:

function squareNums(numArr) {
-  numArr.map(num => {
+  return numArr.map(num => {
    return (num ** 2);
  })
};
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