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

102
Visualizações
mousePressed to for loop

I haven't coded in a long time and I'm pretty rusted. I'm doing a project in which I need to draw a bunch of flight paths from JSON files. For testing, I created this mouse pressed function but I want to automate the process and have the flight path drawn once the previous one is done. I assume I would need nested for loops for it to work but I'm having issues coming up with the loop structure

function mousePressed() {
    if (flightSelector < flightArray[daySelector].length - 1) {
        flightSelector++;
        console.log(flightSelector);
    } else {
        flightSelector = 0
        if (daySelector < dayArray.length - 1) {
            daySelector++;
        }
    }
    getFlightData(dayArray[daySelector], flightArray[daySelector][flightSelector]);
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is a classic scenario for a pair of nested loops. You are running some code repeatedly for each day, and for each day you are running it repeatedly for each flight that happened that day:

for (let daySelector = 0; daySelector < dayArray.length; daySelector++) {
  for (let flightSelector = 0; flightSelector < flightArray[daySelector].length; flightSelector++) {
    getFlightData(dayArray[daySelector], flightArray[daySelector][flightSelector]);
  }
}
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