Skip to content

Instantly share code, notes, and snippets.

@theevilhead
Last active September 24, 2019 17:59
Show Gist options
  • Save theevilhead/62ae52718729b612e75efa3a57deee39 to your computer and use it in GitHub Desktop.
Save theevilhead/62ae52718729b612e75efa3a57deee39 to your computer and use it in GitHub Desktop.
Secret santa mixmatch with google sheets and apps script : Use this script following the instructions in the gist to create a Secret santa mix-match and if needed send each user their partner's details Read whole post here @Hashnode https://hashnode.com/post/secret-santa-mix-match-with-google-sheets-and-apps-script-cjptefe1d00rikas2z9joelqa
/** Dummy data
[email protected] Thomas Bolan  
[email protected] Rafael Ridgley  
[email protected] Shoshana Zarrella  
[email protected] Shavon Cales  
[email protected] Mirian Fasano  
[email protected] Wilfred Patch  
[email protected] Allan Bankes  
[email protected] Edwin Acheson  
[email protected] Emanuel Oriley  
[email protected] Vincenzo Rosenfeld  
[email protected] Kaylene Sauter  
[email protected] Miguel Gerstner  
[email protected] Theresia Heffington  
[email protected] Carl Hendrie  
[email protected] Mazie Kilmon  
[email protected] Marietta Pressman  
[email protected] Tesha Chatham  
[email protected] Erasmo Walcott  
[email protected] Julia Harrah  
[email protected] Deloris Birch  
*/
function readCurrentSheet(){
var currentActiveSheet = SpreadsheetApp.getActiveSheet();
return currentActiveSheet.getDataRange().getValues()
}
function shuffle(array) {
var currentIndex = array.length, temp, randomIndex;
while (0 !== currentIndex){
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temp = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temp;
}
return array;
}
function main(){
var shuffledList = shuffle(readCurrentSheet());
var newSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet('Final List');
var firstHalf = shuffledList.splice(0, shuffledList.length/2);
var newShuffledGivers = [].concat(firstHalf);
var newShuffledGivers = shuffle(newShuffledGivers);
for(var i=0;i<shuffledList.length;i++){
temp = [];
temp = temp.concat(firstHalf[i] || ['','','']).concat(shuffledList[i]).concat(newShuffledGivers[i] || ['','','']);
//firstHalf[i][0] !== '' && MailApp.sendEmail(firstHalf[i][0], 'You secret santa partner', 'Hello there, your secret santa partner is ' + shuffledList[i][1]); // to 1st about 2nd
//newShuffledGivers[i][1] !== '' && MailApp.sendEmail(shuffledList[i][0], 'You secret santa partner', 'Hello there, your secret santa partner is ' + newShuffledGivers[i][1]); // to 2nd about 1st
newSheet.appendRow(temp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment