Last active
October 4, 2015 09:23
-
-
Save pdewouters/5f915904c16056c22af8 to your computer and use it in GitHub Desktop.
Secret santa and code pairing draws
This file contains 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 participants = ["Paul","Matt","Owain","Joe"], | |
results = [], | |
hat = _.shuffle(participants); | |
_.each(participants, function(participant){ | |
var picked = _.sample(_.without(hat,participant)); | |
results.push([participant,picked]); | |
hat = _.without(hat,picked); | |
}); | |
console.log(results); | |
if ( participants.length % 2 === false ){ | |
participants.push("unassigned"); | |
} | |
var pairs = []; | |
function pickFromArr(arr, count) { | |
var pair = _.sample(arr, count); | |
participants = _.filter(arr, function(item){ | |
return ! _.contains(pair,item); | |
}); | |
return pair; | |
} | |
while (participants.length!==0){ | |
pairs.push(pickFromArr(participants,2)); | |
} | |
console.log(pairs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment