Need a bit of help, I have a variable equal to a function, and sometimes it wont resolve and I can't determine why. The code should write pair of names, and array.slice should slowly pair down the arrays, while I also shrink the random number to fit inside the size of the array. I'm hoping someone is going to tell me im missing something obvious. Edit: d and e in the above code are 50/50 either equal to a name from the array or equal to nothing. This is what i can't determine.
var familymembers = ["Frank", "Todd", "Bill", "janice", "marco", "tilly", "monk", "francisco", "james", "bill", "gary"];
var selectedfamilymembers = familymembers;
var itemlength = (familymembers.length);
var m = familymembers[1];
var n = selectedfamilymembers[1];
console.log(m);
console.log(n);
function christmasselector (array1, array2){
let d;
let f;
for (var i = array1.length - 1; i >= 0; i--){
console.log(itemlength);
a = randomizer(itemlength);
b = randomizer(itemlength);
//console.log(a);
//console.log(b);
d = (remover(a, familymembers));
e = (remover(b, selectedfamilymembers));
console.log( "d = " + d);
console.log("e = " + e);
//array1.splice(a, 1);
//console.log(array1);
//array2.splice(b, 1);
//console.log(array2);
itemlength = itemlength - 1;
console.log(d + " -> " + e);
}
}
function remover(selectedspace, array){
console.log("The selected number is " + selectedspace);
return array.splice(selectedspace, 1);
}
function randomizer(rnumber){
return (Math.floor(Math.random() *rnumber));
}
christmasselector (familymembers, selectedfamilymembers);