Skip to content

Instantly share code, notes, and snippets.

@raglan-road
Created January 31, 2018 18:39
Show Gist options
  • Save raglan-road/ef9a427edf201d4f71bbd21d00e91043 to your computer and use it in GitHub Desktop.
Save raglan-road/ef9a427edf201d4f71bbd21d00e91043 to your computer and use it in GitHub Desktop.
var used = [];
var people = {
tony: [],
dan: [],
adam: [],
jamal: [],
kevin: [],
dave: []
}
var toassign = ['tony', 'dan', 'adam', 'jamal', 'kevin', 'dave'];
var max = 5;
for(var i = 1; i < 31; i++){
var cur = Math.round(Math.random() * 30) + 1;
while(used.includes(cur)){
cur = Math.round(Math.random() * 30) + 1;
}
console.log(`picked ${cur}`);
used.push(cur);
var assigned = toassign[Math.round(Math.random() * 5)];
while(people[assigned].length == max){
assigned = toassign[Math.round(Math.random() * 5)];
}
people[assigned].push(cur);
console.log(`${assigned} got ${cur}`)
}
console.log(used);
console.log(people);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment