Skip to content

Instantly share code, notes, and snippets.

@theevilhead theevilhead/
Last active Sep 24, 2019

What would you like to do?
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
/** Dummy data Thomas Bolan Rafael Ridgley Shoshana Zarrella Shavon Cales Mirian Fasano Wilfred Patch Allan Bankes Edwin Acheson Emanuel Oriley Vincenzo Rosenfeld Kaylene Sauter Miguel Gerstner Theresia Heffington Carl Hendrie Mazie Kilmon Marietta Pressman Tesha Chatham Erasmo Walcott Julia Harrah 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.