Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

393
Visualizações
¿Retrasar una función de cadena?

Entonces, básicamente, todo mi código está dentro de un ciclo while. Dentro de eso, tengo un bucle for que busca una abeja en las cuadrículas vecinas. Cuando detecta una abeja llama a una función. Necesito que todas las funciones llamadas por eso esperen y solo se ejecuten cuando el bucle while esté a punto de finalizar (fuera del bucle for pero dentro del bucle while).

Aquí está mi código:

 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 Respostas
Responde à pergunta

0

Almacene en una matriz, luego llame al final.

 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda