title: Generate n sets of unique pairs from an array
body: <p>Trying to generate n sets of unique pairs from an array without repeating items, creating a set of pairs that uses all items in the array only once.</p>
  
  <p>I am working with javascript. I have an array of say 10 items I need to generate the following:</p>
  
  <p>The code I am using gets tripped up like this:</p>
  
  <pre><code>arrPlayers = [1,2,3,4,5,6,7,8,9,10]
  
  matchups-week-1 = [[1,2],[3,4],[5,6],[7,8],[9,10]]
  </code></pre>
  
  <p>matchups-week-2 = [[1,3],[2,4],[5,7],[6,8],[ ooops!! ] can't do [9,10] again so this set won't work.</p>
  
  <p>You see how the 9,10 pair paints the code into a corner? You can only produce 4 pairs because 9,10 is not unique.</p>
  
  <p>I thought this would be easy to work out but I am stuck. Any ideas on code that would not paint itself into this "set of 4" corner?</p>
  
  <p>The code I am using. ...admittedly I am grasping at straws. That's why I am asking the question.</p>
  
  <pre><code>function CreateMatchups(player_ids){
      //Create array of PLAYER IDs where checkbox = checked
      arrPlayers = player_ids.split(", ");
      arrOpponents = arrPlayers;
      arrPrevUsed = GetPrevUsedPairs();
      var arrUsed = [];
      var arrTempMatchups = [];
  
      var intNumPlayers = arrPlayers.length;
      var blnOddNumberOfPlayers = isOdd(intNumPlayers);
  
      if(blnOddNumberOfPlayers){
          arrPlayers.push(9999); //bogus id for placeholder player - fix this
      }
      for (var i = 0; i &lt; arrPlayers.length; i++) { 
          player_id = arrPlayers[i];
          if(!arrUsed.contains(player_id)){
              for (var j = 0; j &lt; arrOpponents.length; j++) { 
                  opponent_id = arrOpponents[j];
                  if((!arrUsed.contains(opponent_id)) &amp;&amp; (!arrUsed.contains(player_id)) &amp;&amp; (player_id != opponent_id)){
                      matchup = player_id + "vs" + opponent_id;
                      if(!arrPrevUsed.contains(matchup)) {
                          arrTempMatchups.push(matchup);
                          arrUsed.push(player_id);
                          arrUsed.push(opponent_id);
                      }
                  }
              }
          }
      }
      return arrTempMatchups;
  
      }
  </code></pre>