Skip to content

Instantly share code, notes, and snippets.

@mdubourg001
Created November 25, 2021 10:46
Show Gist options
  • Save mdubourg001/d5a15d0d3f0f600672dde2c73d678fdc to your computer and use it in GitHub Desktop.
Save mdubourg001/d5a15d0d3f0f600672dde2c73d678fdc to your computer and use it in GitHub Desktop.
Everybody gifts someone randomly for Christmas 🎁
const gifters = [
"Maxime",
"Joffrey",
"Quentin",
"Delphine",
"CΓ©cile",
"Tatie Solange",
"Svetlana"
];
const gifted = [];
const adjectives = ["super", "chouette", "magnifique", "superbe"];
const outputs = [];
function rand(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
for (const gifter of gifters) {
const notAlreadyGifteds = gifters.filter((g) => !gifted.includes(g));
const randomAdjective = rand(adjectives);
let randomGifted = rand(notAlreadyGifteds);
while (randomGifted === gifter) {
randomGifted = rand(notAlreadyGifteds);
}
outputs.push(
`${gifter} offrira un ${randomAdjective} cadeau à ${randomGifted} 🎁`
);
gifted.push(randomGifted);
}
console.log(outputs.join("\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment