title: Loop in array return wrong number of array
body: <p>I've this function that return me a group of array. Each array contain a list of teams. If the teams are more than 4, the result of array not is equal for each of it. In the example below, with 12 teams, it return me 12 array in total, 3 with 12 teams and 9 with 8 teams ( 3 teams are missing during the loop on each array, after the 3rd ). If i add only 4 teams, it work. How i can fix that ?</p>
  <pre><code>let teams = [&quot;Team_1&quot;, &quot;Team_2&quot;, &quot;Team_3&quot;, &quot;Team_4&quot;,&quot;Team_5&quot;, &quot;Team_6&quot;, &quot;Team_7&quot;, &quot;Team_8&quot;,&quot;Team_9&quot;, &quot;Team_10&quot;, &quot;Team_11&quot;, &quot;Team_12&quot;];
      
  teams = teams.map(id =&gt; ({id}));
  
  teams.forEach(team =&gt; team.enemies = teams.filter(enemy =&gt; enemy !== team));
      
  const matches = [];
      
  while(teams.some(team =&gt; team.enemies.length)) {
    const playing = [];
  
    for(const team of teams){
      if(playing.includes(team)) continue;
      const enemy = team.enemies.find(enemy =&gt; !playing.includes(enemy)); 
      if(!enemy) continue;
      const indexTeam = team.enemies.indexOf(enemy)
      const indexEnemy = enemy.enemies.indexOf(team)
      
      team.enemies.splice(indexTeam,1);
      enemy.enemies.splice(indexEnemy, 1);
      
      playing.push(team, enemy);
    }
      
    if(playing.length) matches.push(playing.map(t =&gt; t.id))
  }
      
  console.log(matches);
  </code></pre>