Last active
November 26, 2015 06:32
-
-
Save wesleycho/7fe0405e04720a98b9ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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); | |
} | |
} | |
} |
This file contains hidden or 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
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