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

110
Visualizações
How do I sort a javascript 2d array of names into groups?

I have a race consisting of (for example) 9 heats. There are (for example) 9 drivers split in to groups. In this example, each driver will drive in 4 heats each. However, I don't know ,explicitly, how many groups there are and I don't know how many drivers are in each group.

What I do know, is which heat each driver is in. So, for this example the heats may look like this: enter image description here

So, how do I determine how many groups there are and how do I get the drivers in to their respective groups?

Also, how do I make this generic, so that it could be 8 drivers in 8 heats or 37 drivers in 29 heats?

In javascript, so far, I have populated a 2D array that gives results similar to the grid shown above.

Here is the code I have so far:

for (var i = 0; i < heatData.cnt; i++)           //number of heats                                              
{
    var driverArray = new Array();
    for (var k = 0; < json.r[1].d.length ; k++)  //number of drivers in this heat.
    {
        var name = json.r[1].d[k].nn;            //this is the name of the driver in this heat.
        driverArray[k] = name;                   //adds the name to the inner array
    }
    heatArray.push(driverArray);                 //adds the inner array to the end of the outer array.
    });

}

Thanks,

Connal

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