Hice esta función para generar accesorios personalizados, pero tengo un problema si los jugadores en las rondas son más de 8. Intenté agregar 10 jugadas en lugar de 8, y el ciclo me devolvió un resultado incorrecto.
let teams = [ { id: "Team1" }, { id: "Team2" }, { id: "Team3" }, { id: "Team4" }, { id: "Team5" }, { id: "Team6" }, { id: "Team7" }, { id: "Team8" }, {id: "Team9" }, {id: "Team10" } ] // Total rounds let totRounds = 3 // Array with rounds let rounds = [] for (let i = 0; i < totRounds; i++) { // This loop add an array on enemyes teams enemies["team2,..."] teams.forEach(team => team.enemies = teams.filter(enemy => enemy !== team)); // Empty Array for first round const matches = []; // Empty Array for second round ( return ) const matches_return = []; while (teams.some(team => team.enemies.length)) { const playing = []; const playing_return = [] for (const team of teams) { //debugger if (playing.includes(team)) continue; const enemy = team.enemies.find(enemy => !playing.includes(enemy)); if (!enemy) continue; team.enemies.splice(team.enemies.indexOf(enemy), 1); enemy.enemies.splice(enemy.enemies.indexOf(team), 1); playing.push(team, enemy); playing_return.push(enemy, team); } if (playing.length) matches.push(playing.map(t => t.id)) if (playing_return.length) matches_return.push(playing_return.map(t => t.id)) } // Merge 2 arrays const totalMatches = matches.concat(matches_return) rounds.push(totalMatches); } console.log(rounds);Esto funciona con 8 jugadores, pero con 10 o más no. Intenté hacer algunos cambios pero no funcionaron.