Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!