Created
November 25, 2021 10:46
-
-
Save mdubourg001/d5a15d0d3f0f600672dde2c73d678fdc to your computer and use it in GitHub Desktop.
Everybody gifts someone randomly for Christmas π
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 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