Last active
August 14, 2018 02:41
-
-
Save vhmolinar/be535866d033ab7d4cad5ff4476cebec to your computer and use it in GitHub Desktop.
Sorteio de instrutores para curso na casa espírita
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
(() => { | |
'use strict'; | |
const pessoas = [ 'Tarsila', | |
'Victor Hugo', | |
'Josue', | |
'Diego', | |
'Nicollas', | |
'Khal', | |
'Rodrigo', | |
'Luana', | |
'Lucas', | |
'Leonardo', | |
'Thulio', | |
'Gloria', | |
'Mauro', | |
'Thiago', | |
'Gabriela', | |
'Michael', | |
'Alixandre' ]; | |
function getRandom() { | |
return Math.floor(Math.random() * pessoas.length); | |
} | |
function exec() { | |
const aulas = 14, | |
temas = [ | |
'Nas telas do Infinito', | |
'Brasil, Coração do Mundo, Pátria do Evangelho', | |
'Tema Atual' | |
]; | |
const aulasSorteadas = []; | |
temas.forEach((tema, j) => { | |
let idx = {}; | |
for (let i=0; i<aulas; ++i) { | |
if ( Object.keys(idx).length === pessoas.length ) { | |
idx = {}; | |
} | |
var index = null; | |
do { | |
index = getRandom(); | |
} while( idx[index] == true ); | |
idx[index] = true; | |
if (!aulasSorteadas[i]) { | |
aulasSorteadas[i] = {}; | |
} | |
const aula = aulasSorteadas[i]; | |
aula[tema] = pessoas[index]; | |
} | |
}); | |
aulasSorteadas.forEach((aula, i) => { | |
let tx = `Aula ${i} `; | |
for (let tema in aula) { | |
const pessoa = aula[tema]; | |
tx += ` - [ ${tema} - ${pessoa} ]`; | |
} | |
console.log(tx); | |
}); | |
} | |
console.log('Trust me, it is random\n\n'); | |
exec(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment