Last active
September 30, 2021 17:26
-
-
Save jaredririe/7b76eb51e07f05d983cf147b388a5694 to your computer and use it in GitHub Desktop.
Cousin Gift Exchange (ensures that gifts are only given to cousins, not siblings)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const _ = require('lodash'); | |
| const families = [ | |
| [ | |
| { name: "Corbyn", giftFrom: "" }, | |
| { name: "Peyton", giftFrom: "" }, | |
| { name: "Logan", giftFrom: "" }, | |
| { name: "Easton", giftFrom: "" } | |
| ], | |
| [ | |
| { name: "Blake", giftFrom: "" }, | |
| { name: "Skyler", giftFrom: "" }, | |
| { name: "Grey", giftFrom: "" }, | |
| { name: "Axel", giftFrom: "" } | |
| ], | |
| [ | |
| { name: "Madison", giftFrom: "" }, | |
| { name: "Linnea", giftFrom: "" } | |
| ] | |
| ]; | |
| _.forEach(families, (family, i) => { | |
| _.forEach(family, (member) => { | |
| const otherFamilies = _.filter(families, (_, idx) => { | |
| return idx != i; | |
| }) | |
| while (true) { | |
| const anotherFamily = _.sample(otherFamilies); | |
| const randomCousin = _.sample(anotherFamily); | |
| if (randomCousin.giftFrom == "") { | |
| console.log(`${member.name} giving to ${randomCousin.name}`); | |
| randomCousin.giftFrom = member.name; | |
| break; | |
| } | |
| } | |
| }) | |
| }) |
Author
Author
Output 2019
Corbyn giving to Grey
Peyton giving to HobbsBaby
Logan giving to Madison
Easton giving to Blake
Blake giving to Easton
Skyler giving to Corbyn
Grey giving to Linnea
HobbsBaby giving to Peyton
Madison giving to Skyler
Linnea giving to Logan
Author
Output 2020
Corbyn giving to Linnea
Peyton giving to Grey
Logan giving to Skyler
Easton giving to Axel
Blake giving to Easton
Skyler giving to Peyton
Grey giving to Logan
Axel giving to Madison
Madison giving to Blake
Linnea giving to Corbyn
Author
Output 2020
Jared giving to Timothy
Cailey giving to Matt
Timothy giving to Elise
Claudia giving to Jared
Matt giving to Cailey
Elise giving to Claudia
Author
Output 2021
Corbyn giving to Grey
Peyton giving to Blake
Logan giving to Linnea
Easton giving to Axel
Blake giving to Madison
Skyler giving to Logan
Grey giving to Easton
Axel giving to Corbyn
Madison giving to Peyton
Linnea giving to Skyler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output 2018