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

387
Vistas
Delaying a string function?

So basically I all my code is within a while loop. Within that I have a for loop which checks for a bee in the neighboruging grids. When it detects a bee it calls a function. I need all the functions called by that to wait and only run when the while loop is just about to be finsihed (outside the for loop but inside the while loop).

Here is my code:

Cell.prototype.floodFillEach = function() {
  grid[orginalX][orginalY].floodFill();
  while(repeat<=7){
    for (var xoff = 0-x12; xoff <= 0+x12; xoff++) {
      for (var yoff = 0; yoff <= 0+x12; yoff++) {
        var i = orginalX + xoff;
        var j = orginalY + yoff;
        if (i > -1 && i < cols && j > 0 && j < rows) {
          var neighbour = grid[i][j];
          if (neighbour.marked2) {
            console.log("x:"+i+"  y:"+j);
            neighbour.floodFill(); // everytime this function is called within this while loop i need it to wait untill...       
          }
        }
      }
    }
      // ... here. I need the functions called to wait and run here and after they are done only then proceed with the rest of this while loop
    x12++
    repeat++
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Store in an array, then call at the end.

Cell.prototype.floodFillEach = function() {
  grid[orginalX][orginalY].floodFill();
  while(repeat<=7){
    const neighboursToFloodFill = [];
    for (var xoff = 0-x12; xoff <= 0+x12; xoff++) {
      for (var yoff = 0; yoff <= 0+x12; yoff++) {
        var i = orginalX + xoff;
        var j = orginalY + yoff;
        if (i > -1 && i < cols && j > 0 && j < rows) {
          var neighbour = grid[i][j];
          if (neighbour.marked2) {
            console.log("x:"+i+"  y:"+j);
            neighboursToFloodFill.push(neighbour);     
          }
        }
      }
    }
    for (const neighbour of neighboursToFloodFill) {
      neighbour.floodFill();
    }
    x12++
    repeat++
  }
}
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