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

109
Vistas
My browser lags when I try a loop function?

I wrote a simple nested loop function to multiply all items in an array and output the total value, but each time is I run a loop function my browser either crashes or doesn't stop loading

function multiplyAll(arr){ 
        Let product = 1;
       for(let i = 0; i < 
            arr.length; i++){
            for(let j = 0; j < 
     arr[i].length; j *= product);
     }
      return product;
}

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

0

You are creating an infinite loop here because of

for (let j = 0; j < arr[i].length; j *= product);

Here, j is always 0.

If you want to multiply all the nested value then you should do as:

function multiplyAll(arr) {
  let product = 1;
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; ++j)
      product *= arr[i][j];
  }
  return product;
}

console.log(multiplyAll([[1], [2], [3]]));


If you just want to multiple all the nested value then you can simply do as:

function multiplyAll(arr) {
  return arr.flat().reduce((acc, curr) => acc * curr, 1);
  // If you want to get numbers at any depth then you can flat at any level
  // using Infinity as
  // return arr.flat(Infinity).reduce((acc, curr) => acc * curr, 1);
}

console.log(multiplyAll([[1], [2], [3]]));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Well, it looks like you have multiple issues, two of them are already as following:

  1. In line 2 you wrote once Let with a big letter at the beginning.
  2. Your second array needs an {} otherwise it will error out
  3. Can you please explain to me j*= product? Can you maybe include a few examples of how you would call this Code and what kind of response you would get? depending on that I will create you a Clear answer!
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