I am making a tournament bracket generator. Currently, I am working on the logic for this program in JavaScript. So far, I have separate arrays for different team classifications –
let winners = [];
let losers = [];
let eliminated = [];
As this is a double elimination bracket, winners have 0 losses, losers have 1 loss, and eliminated have 2 losses. My goal is to have each array create “matches” (pairs within the array (like [1] vs [2], [3] vs [4], etc. etc.)).
I am trying to make the program move team objects between arrays so that the proper teams are being utilized when making matches and determining whether they fall into the loser’s bracket or the winner’s bracket. Using some logic from a GitHub repo I have –
teams[//8 teams];
function makeMatches (array) {
structuredClone(array).forEach((team, i, teams) => {
team.opponent = teams[i + (i % 2 === 0 ? 1 : -1)]; //GitHub repo
});
function bracketMatches(team) {
if (team.losses === 0) {
//move to winners
makeMatches(winners);
}
if (team.losses === 1) {
//move to losers
makeMatches(losers);
}
if (team.losses === 2) {
//move to eliminated;
}
}
How do I move the object from one array to another? Also any input on my logic or solution would be greatly appreciated, I just started programming so I’m sure there is a better way to do this out there 🙂