Skip to content

Instantly share code, notes, and snippets.

@bryanforbes
Last active December 15, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanforbes/5196843 to your computer and use it in GitHub Desktop.
Save bryanforbes/5196843 to your computer and use it in GitHub Desktop.
function secretSanta(array) {
var year = (new Date).getYear(),
offset = year % array.length,
map = {};
array.forEach(function (item, index) {
map[item] = array[index + offset] || array[array.length - (index + offset)];
});
return map;
}
function secretSanta(array) {
var map = {},
giveTo = array.slice(0);
giveTo.unshift(giveTo.pop());
array.forEach(function (item, index) {
map[item] = giveTo[index];
});
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment