Last active
June 8, 2021 08:32
-
-
Save danielgynn/b7a966a3647dd6445928fadbc3e742be to your computer and use it in GitHub Desktop.
Euro 2020 Sweepstakes Generator
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 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run:
node euroSweepstakes.js Name1 Name2 Name3 Name4