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

322
Visualizações
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
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