-2
 I’m managing to generate matches and display on the screen. But it happens that a same ski can not play in the same round.
I’m managing to generate matches and display on the screen. But it happens that a same ski can not play in the same round.
I created a function verificarRodada() to avoid this, but she doesn’t seem to be avoiding. Someone helps?
 function gerarRodadas(arrTimes, arrPartidas)
  {
       qtd_total_partidas = arrPartidas.length;
       qtd_rodadas = (arrTimes.length-1)*2;
       qtd_partidas_por_rodada = arrTimes.length/2;
       arr_pos = new Array(qtd_total_partidas);     
       iniciarArray(arr_pos, qtd_total_partidas);
       for(i=0; i<qtd_rodadas; i++)
       {   
             cond=0;
             while(cond < qtd_partidas_por_rodada)
            {
              rand = Math.floor(Math.random() * qtd_total_partidas);
              if(arr_pos[rand] == 0) 
              {
                if(verificarRodada(i, this.arrRodadas, arrPartidas[rand]))
                {
                    mandante = arrPartidas[rand].mandante;
                    visitante = arrPartidas[rand].visitante;
                    estado = arrPartidas[rand].estado;                  
                    this.arrRodadas.push(new Array(i, mandante, visitante, estado));
                    arr_pos[rand] = 1;    
                    cond++;
                 }
               } 
             }
        }
        this.arrRodadas.forEach(rodada => {
          part = "Rodada : " + (rodada[0]+1) + " - " + rodada[1] + " vs " + rodada[2] + " - " + rodada[3];
          criarElemento("add_partidas", "p", part);
        })     
  }
  function verificarRodada(rodada, rodadas, partida)
  {
     mandante = partida.mandante;
     visitante = partida.visitante;
     rodadas.forEach(item  => {
        if(item[0] == rodada)
        {
          if(item[1] == mandante || item[1] == visitante || item[2] == mandante || item[2]== visitante)
          {
            return false;
          }
        }
     })
     return true;
  }
Still the same problem. Prints the games, but this letting the same team play twice in the same round.
– Lorram RJ