Very much a novice, my fixture and league table program works fine with hardcoded fixtures but attempting a more flexible code that builds fixtures round by round has broken it.
You'll see I've coded both methods, and use the flag 'hardFix' to determine how the fixtures are built.
var players = ["P1", "P2", "P3"];
var Fixtures = [];
var rounds = 3;
var hardFix = false;
function buildFixtures() {
if (hardFix == true) {
Fixtures = [
[players[0], , , players[1]],
[players[0], , , players[2]],
[players[1], , , players[2]],
[players[1], , , players[0]],
[players[2], , , players[0]],
[players[2], , , players[1]],
[players[0], , , players[1]],
[players[0], , , players[2]],
[players[1], , , players[2]],
[players[1], , , players[0]],
[players[2], , , players[0]],
[players[2], , , players[1]],
];
} else {
let oddRound = [
[players[0],,,players[1]],
[players[0],,,players[2]],
[players[1],,,players[2]]
];
let evenRound = [
[players[1],,,players[0]],
[players[2],,,players[0]],
[players[2],,,players[1]]
];
for (let i = 1; i <= rounds; i++) {
if (i & 1) {
Array.prototype.push.apply(Fixtures, oddRound);
} else {
Array.prototype.push.apply(Fixtures, evenRound);
}
}
}
}
You'll see below:
- with two rounds there's not a problem
- when there's more, the first round becomes 'invisible'
- and the final fixture's result gets dupicated (see whole array below table)
I believe it's something to do with the structure of the array that I've built. Any advice apprecitated. Thanks in advance