Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Last active October 4, 2015 09:23
Show Gist options
  • Save pdewouters/5f915904c16056c22af8 to your computer and use it in GitHub Desktop.
Save pdewouters/5f915904c16056c22af8 to your computer and use it in GitHub Desktop.
Secret santa and code pairing draws
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