Last active
December 8, 2015 11:23
-
-
Save felipenmoura/2a004604ca4cef39cc80 to your computer and use it in GitHub Desktop.
Função utilizada para sortear entre os participantes na lista da eventick (em checkin.eventick.com.br)
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
function selectOne(){ | |
var x= [].slice.call(document.querySelectorAll('.tml-attendees-checked td:nth-child(2) strong')).map(function (cur){return cur.innerText;}); | |
var picked = x[ Math.ceil(Math.random() * x.length) ]; | |
console.log("%c" + picked, "font-weight: bold; color: red; font-size: 40px;"); | |
return picked; | |
} | |
function selectAsMany(howMany){ | |
var picked = [], | |
lastSelected, | |
cur = 0, | |
limit = 100; | |
while(picked.length < howMany){ | |
cur++; | |
lastSelected = selectOne(); | |
if(picked.indexOf(lastSelected) < 0){ | |
picked.push(lastSelected); | |
} | |
if(cur >= limit){ | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment