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

211
Vistas
How to perform 2 functions one after the other with forEach, without looping twice?

Does anyone know how can I do the same thing as that :

Player.list.forEach(player => {
    player.firstLayer();
});

Player.list.forEach(player => {
    player.secondLayer();
});

But looping it only one time to make it faster.

(I want to execute all firstLayer function of all players, and then execute secondLayer function, but without looping it Player.list two times)

Thanks for answer.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is not possible and there is no real difference in performance. The Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. There is no difference between running over the loop once or twice. The difference of O(n) vs O(2n) in terms of asymptotic complexity doesn't exist since both have the "linear" growth rate.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The only thing you can do is

Player.list.forEach(player => {
  player.firstLayer();
  player.secondLayer();
});

but this will execute directly the second layer immediately after the first layer for each element. If the second layer for every element is different you cannot do what you want without looping again.

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