Skip to content

Instantly share code, notes, and snippets.

@web20opensource
Last active August 29, 2015 14:27
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 web20opensource/070dd52cd1728684debc to your computer and use it in GitHub Desktop.
Save web20opensource/070dd52cd1728684debc to your computer and use it in GitHub Desktop.
var comments = document.querySelectorAll('#comment-list > li');
var winners = {};
getWinnerComment = function(id) {
return document.querySelectorAll('#' + id + ' .comment-content p')[0].textContent;
}
var iterations = 10000;
while(iterations--){
var commentsList = [];
var array = new Uint32Array(comments.length);
var randomIds = window.crypto.getRandomValues(array);
Array.prototype.forEach.call(comments, function(el, i){
if (el.id) commentsList.push({id: el.id, rand: randomIds[i]});
});
commentsList.sort(function(a, b) {
return a.rand - b.rand;
});
winners [commentsList[2].id] = Number(winners [commentsList[2].id])+1 || 1;
winners [commentsList[1].id] = Number(winners [commentsList[1].id])+1 || 1;
winners [commentsList[0].id] = Number(winners [commentsList[0].id])+1 || 1;
}
console.dir(winners)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment