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

321
Views
How do you loop through multiple arrays and gather data from each one based on a given number of iterations? Either JS, Java, or C++

I'm writing this in JS but anything similar in Java or C++ would work too! So essentially I need to gather values from multiple arrays based on a given number of iterations. The best way I can describe this is like a calendar. I similarly have an array for days, weeks, months, and years:

const days = ["S", "M", "T", "W", "T", "F", "S"];
const weeks = ["Week 1", "Week 2", "Week 3", "Week 4"];
const months = ["Jan", "Feb", "Mar", "Apr", "May"...];
const years = ["2000", "2001", "2002", "2003", "2004"...];

The idea is to find the date from given number of total days. For example, 30 days (assuming there are exactly 4 weeks in a month in this application) would loop through the days array 30 times, through the weeks 4 times, and through the month one time to gather the array vales as "M, Week 1, Feb, 2000". The part I am struggling with is I have nested loops, but once I have iterated through the 30 days, I need the loops to stop where they are and print/log the values they are currently on.

while (totalDays > 0) {
   for (let i = 0; i < totalDays < 7; i++) {
      day = days[i];
      totalDays -= 1;
      if (totalDays == 0) {
        break;
      }
         for (let i = 0; i < totalDays / 7; i++) {
            week = weeks[i];
            totalDays = -1;
            if (totalDays == 0) {
            break;
            }

             for (let i = 0; i < totalDays / 12; i++) {
                 week = weeks[i];
                 totalDays = -1;
                 if (totalDays == 0) {
                    break;
                 }

                 for (let i = 0; i < totalDays / 365; i++) {
                     week = weeks[i];
                     totalDays = -1;
                     if (totalDays == 0) {
                        break;
                     }
                 }
             }
         }
     }
}

So how do I make this loop like a big clock or calendar that will loop through and stop at a given number of increments and output the exact times/values in each array?

Any help is much appreciated! Thanks.

about 4 years ago · Juan Pablo Isaza
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!