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
When using Array.map() followed by a for loop on that same array, is it double work?

I'm perplexed why a previous engineer wrote some code that looks like double work to me. Could you not just do either the accounts.map() or the for (const acct of accounts)? Why both?

const accounts = await mongohelper.find(conn, 'accounts', query, 2000);
if(!accounts.length){return;}
const arrayofwork = accounts.map(act => salesmanwork(act, conn))


for (const act of accounts) {
    arrayofwork.push(salesmanwork(act, conn));
}

await Promise.allSettled(arrayofwork)
return await recursivecall(workitemin, count);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's making a duplication of the processed values from the accounts array by salesmanwork function. Maybe that's what's intended or might be a bug, some code that they didn't remove.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Output is basically the same, the only differences are speed, readability and functionality, which barely differ. What I mean by this is that when using .map() it returns an array, in where you can use it in one-liners and promises, while in for loops, you need to initialize, then make the loop, and return the same value.

In this case, it is probably some code someone forgot to clean up; either works, the only differences are readability. If you are using a bigger array, use the for loop, otherwise it's up to you.

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