Last active
August 29, 2015 14:27
-
-
Save web20opensource/070dd52cd1728684debc to your computer and use it in GitHub Desktop.
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
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