Skip to content

Instantly share code, notes, and snippets.

@wesleycho
Last active November 26, 2015 06:32
Show Gist options
  • Save wesleycho/7fe0405e04720a98b9ac to your computer and use it in GitHub Desktop.
Save wesleycho/7fe0405e04720a98b9ac to your computer and use it in GitHub Desktop.
function matchPeople (list, idx) {
var randomNumber = Math.floor(Math.random() * list.length);
if (list[randomNumber] === list[idx]) {
return matchPeople(list, idx);
}
else {
idx++;
$scope.match.push(list[randomNumber]);
if (list.length === 1) {
return;
}
else {
var clonedList = _(list).cloneDeep();
clonedList.splice(randomNumber, 1);
return matchPeople(clonedList, idx);
}
}
}
function matchPeople(list, matches) {
if (!list.length) {
return;
}
var randomNum = Math.floor(Math.random() * list.length);
if (list[randomNum] !== matches[randomNum]) {
Array.prototype.push.apply(matches, list.splice(randomNum, 1));
}
return matchPeople(list, matches);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment