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:

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