Created
April 27, 2016 13:11
-
-
Save pfirpfel/0bbd9d9b7ca53d69d617294326903ada to your computer and use it in GitHub Desktop.
Round Robin Pairings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var players = ['A', 'B', 'C', 'D', 'E', 'F', 'G' ]; | |
var generateRounds = function(players, bye){ | |
// add bye to rotation if number of players is odd | |
if(players.length % 2 == 1){ | |
players.push(bye); | |
} | |
// first player does not rotate | |
var first = players.shift(); | |
// output | |
var rounds = []; | |
// create paired rounds | |
for(var i = 0; i < players.length; i++){ | |
var currentPlayers = [].concat(first, players); | |
var currrentRound = []; | |
while(currentPlayers.length > 0){ | |
currrentRound.push([currentPlayers.shift(), currentPlayers.pop()]); | |
} | |
rounds.push(currrentRound); | |
// rotate players | |
players.push(players.shift()) | |
} | |
return rounds; | |
} | |
generateRounds(players, 'BYE'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment