Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. var participants = ["Paul","Matt","Owain","Joe"],results = [];
  2. var hat = _.shuffle(participants);
  3. _.each(participants, function(participant){
  4. var picked = _.sample(_.without(hat,participant));
  5. results.push([participant,picked]);
  6. hat = _.without(hat,picked);
  7.  
  8. });
  9. console.log(results);
  10. // each participant
  11.  
  12. if ( participants.length % 2 === false ){
  13. participants.push("unassigned");
  14.  
  15. }
  16.  
  17. var pairs = [];
  18.  
  19. // Pick n items from array
  20. function pickFromArr(arr, count) {
  21. var pair = _.sample(arr, count);
  22. participants = _.filter(arr, function(item){
  23. return ! _.contains(pair,item);
  24. });
  25. return pair;
  26. }
  27.  
  28. while (participants.length!==0){
  29. pairs.push(pickFromArr(participants,2));
  30. }
  31. console.log(pairs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement