Skip to content

Instantly share code, notes, and snippets.

@danielgynn
Last active June 8, 2021 08:32
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 danielgynn/b7a966a3647dd6445928fadbc3e742be to your computer and use it in GitHub Desktop.
Save danielgynn/b7a966a3647dd6445928fadbc3e742be to your computer and use it in GitHub Desktop.
Euro 2020 Sweepstakes Generator
const countries = [
'๐Ÿ‡ฆ๐Ÿ‡น Austria', '๐Ÿ‡ง๐Ÿ‡ช Belgium', '๐Ÿ‡ญ๐Ÿ‡ท Croatia', '๐Ÿ‡จ๐Ÿ‡ฟ Czech Republic', '๐Ÿ‡ฉ๐Ÿ‡ฐ Denmark',
'๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ England', '๐Ÿ‡ซ๐Ÿ‡ฎ Finland', '๐Ÿ‡ซ๐Ÿ‡ท France', '๐Ÿ‡ฉ๐Ÿ‡ช Germany', '๐Ÿ‡ญ๐Ÿ‡บ Hungary',
'๐Ÿ‡ฎ๐Ÿ‡น Italy', '๐Ÿ‡ณ๐Ÿ‡ฑ Netherlands', '๐Ÿ‡ฒ๐Ÿ‡ฐ North Macedonia', '๐Ÿ‡ต๐Ÿ‡ฑ Poland',
'๐Ÿ‡ต๐Ÿ‡น Portugal', '๐Ÿ‡ท๐Ÿ‡บ Russia', '๐Ÿด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ Scotland', '๐Ÿ‡ธ๐Ÿ‡ฐ Slovakia', '๐Ÿ‡ช๐Ÿ‡ธ Spain',
'๐Ÿ‡ธ๐Ÿ‡ช Sweden', '๐Ÿ‡จ๐Ÿ‡ญ Switzerland', '๐Ÿ‡น๐Ÿ‡ท Turkey', '๐Ÿ‡บ๐Ÿ‡ฆ Ukraine', '๐Ÿด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ Wales'
];
const runSweepstake = () => {
const contenders = process.argv.slice(2);
const output = contenders.map(name => {
return {
name,
countries: []
};
});
while (countries.length) {
shuffle(output);
output.forEach((_o, index) => {
const randomCountry = countries[Math.floor(Math.random() * countries.length)];
if (randomCountry) {
output[index].countries.push(randomCountry);
countries.splice(countries.indexOf(randomCountry), 1);
}
});
}
output.forEach(o => {
console.log(`${o.name} has drawn: ${o.countries.join(', ')}`)
});
};
const shuffle = (array = []) => {
let currentIndex = array.length,
randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]
];
}
return array;
};
runSweepstake();
@danielgynn
Copy link
Author

To run: node euroSweepstakes.js Name1 Name2 Name3 Name4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment