function createSecretSantaNames(){
        var selector;
        var userIndex;
        var retryCount = 0;

        for (var i = 0; i < optInUserArr.length; i++) {
            selector = Math.floor((Math.random() * tempUserArr.length));
            if (!userUIDArr.includes(tempUserArr[selector].uid)) {
                if (tempUserArr[selector].name != optInUserArr[i].name) {
                    if (optInUserArr[i].friends.includes(tempUserArr[selector].uid)) {
                        console.log("Matched " + tempUserArr[selector].name + " to " + optInUserArr[i].name);
                        userUIDArr.push(tempUserArr[selector].uid);
                        userIndex = findUIDItemInArr(optInUserArr[i].uid, userArr);
                        userArr[userIndex].secretSantaName = tempUserArr[selector].uid;
                        tempUserArr.splice(selector, 1);
                        retryCount = 0;
                    } else {
                        //console.log("These Users Aren't Friends :(");
                        retryCount++;
                        if(retryCount >= 10)
                            break;
                        i--;
                    }
                } else {
                    //console.log("These Are The Same Users :(");
                    retryCount++;
                    if(retryCount >= 10)
                        break;
                    i--;
                }
            } else {
                //console.log("User Has Already Been Picked");
                retryCount++;
                if(retryCount >= 10)
                    break;
                i--;
            }
        }

        if (optInUserArr.length != userUIDArr.length) {
            console.log("USERUIDARR:");
            console.log(userUIDArr);
            console.log("TEMPUSERARR:");
            console.log(tempUserArr);
            userUIDArr = [];
            removeSecretSantaNames();
            alert("Secret Santa System Was Unable To Properly Initialize Secret Santa Names. Please Try Again");
        } else {
            sessionStorage.setItem("userArr", JSON.stringify(userArr));
            updateAllUsersToDBSantaNames();
            userUIDArr = [];
        }
    }
//This function randomly assigns Secret Santa names and checks to make sure that everyone is assigned a name
This function randomly assigns Secret Santa names and checks to make sure that everyone is assigned a name
This function randomly assigns Secret Santa names and checks to make sure that everyone is assigned a name
function createSecretSantaNames(){
        var selector;
        var userIndex;
        var retryCount = 0;
        for (var i = 0; i < optInUserArr.length; i++) {
            selector = Math.floor((Math.random() * tempUserArr.length));
            if (!userUIDArr.includes(tempUserArr[selector].uid)) {
                if (tempUserArr[selector].name != optInUserArr[i].name) {
                    if (optInUserArr[i].friends.includes(tempUserArr[selector].uid)) {
                        console.log("Matched " + tempUserArr[selector].name + " to " + optInUserArr[i].name);
                        userUIDArr.push(tempUserArr[selector].uid);
                        userIndex = findUIDItemInArr(optInUserArr[i].uid, userArr);
                        userArr[userIndex].secretSantaName = tempUserArr[selector].uid;
                        tempUserArr.splice(selector, 1);
                        retryCount = 0;
                    } else {
                        retryCount++;
                        if(retryCount >= 10)
                            break;
                        i--;
                    }
                } else {
                    retryCount++;
                    if(retryCount >= 10)
                        break;
                    i--;
                }
            } else {
                retryCount++;
                if(retryCount >= 10)
                    break;
                i--;
            }
        }
        if (optInUserArr.length != userUIDArr.length) {
            console.log("USERUIDARR:");
            console.log(userUIDArr);
            console.log("TEMPUSERARR:");
            console.log(tempUserArr);
            userUIDArr = [];
            removeSecretSantaNames();
            alert("Secret Santa System Was Unable To Properly Initialize Secret Santa Names. Please Try Again");
        } else {
            sessionStorage.setItem("userArr", JSON.stringify(userArr));
            updateAllUsersToDBSantaNames();
            userUIDArr = [];
        }
    }
function createSecretSantaNames ( ) { var selector ; var userIndex ; var retryCount = 0 ; for ( var i = 0 ; i < optInUserArr . length ; i ++ ) { selector = Math . floor ( ( Math . random ( ) * tempUserArr . length ) ) ; if ( ! userUIDArr . includes ( tempUserArr [ selector ] . uid ) ) { if ( tempUserArr [ selector ] . name != optInUserArr [ i ] . name ) { if ( optInUserArr [ i ] . friends . includes ( tempUserArr [ selector ] . uid ) ) { console . log ( "Matched " + tempUserArr [ selector ] . name + " to " + optInUserArr [ i ] . name ) ; userUIDArr . push ( tempUserArr [ selector ] . uid ) ; userIndex = findUIDItemInArr ( optInUserArr [ i ] . uid , userArr ) ; userArr [ userIndex ] . secretSantaName = tempUserArr [ selector ] . uid ; tempUserArr . splice ( selector , 1 ) ; retryCount = 0 ; } else { retryCount ++ ; if ( retryCount >= 10 ) break ; i -- ; } } else { retryCount ++ ; if ( retryCount >= 10 ) break ; i -- ; } } else { retryCount ++ ; if ( retryCount >= 10 ) break ; i -- ; } } if ( optInUserArr . length != userUIDArr . length ) { console . log ( "USERUIDARR:" ) ; console . log ( userUIDArr ) ; console . log ( "TEMPUSERARR:" ) ; console . log ( tempUserArr ) ; userUIDArr = [ ] ; removeSecretSantaNames ( ) ; alert ( "Secret Santa System Was Unable To Properly Initialize Secret Santa Names. Please Try Again" ) ; } else { sessionStorage . setItem ( "userArr" , JSON . stringify ( userArr ) ) ; updateAllUsersToDBSantaNames ( ) ; userUIDArr = [ ] ; } }
This function randomly assigns Secret Santa names and checks to make sure that everyone is assigned a name
This function randomly assigns Secret Santa names and checks to make sure that everyone is assigned a name
//console.log("These Users Aren't Friends :("); //console.log("These Are The Same Users :("); //console.log("User Has Already Been Picked");