Created
November 29, 2018 17:52
-
-
Save g1stavo/9f71c5e11c29cd3666efc6ee4a6705b7 to your computer and use it in GitHub Desktop.
$ groups=X min=X node randomizer.js
This file contains 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 env_groups = process.env.groups; | |
const env_min = process.env.min; | |
let participants = [ | |
'Juliana', | |
'Christian', | |
'Gleice', | |
'Gustavo', | |
'Denise', | |
'Eduardo', | |
'Fernanda', | |
'João', | |
'Gilmar', | |
'Lucas' | |
]; | |
let groups = []; | |
for (let i = 0; i < env_groups; i++) { | |
let temp = []; | |
for (let j = 0; j < env_min; j++) { | |
let random = participants[Math.floor(Math.random() * participants.length)]; | |
temp.push(random); | |
participants = participants.filter(item => { | |
return item !== random; | |
}); | |
} | |
groups.push(temp); | |
} | |
groups.forEach((item, index) => { | |
console.log(item); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment