Skip to content

Instantly share code, notes, and snippets.

@toymachiner62
Created November 11, 2013 14:26
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 toymachiner62/7413916 to your computer and use it in GitHub Desktop.
Save toymachiner62/7413916 to your computer and use it in GitHub Desktop.
This is a Fantasy Football draft order randomizer. This app that takes an array of names and displays them in a random order every time the page is refreshed.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function() {
var players = new Array("Tom", "Kraig", "PT", "Chanse", "Young", "Grant", "Paul", "JJ", "Ty", "Jason");
var draftOrder = shuffle(players);
for(var index in draftOrder) {
$('#order').append('<li>#' + ++index + " " + draftOrder[--index] + '</li>');
}
});
// Shuffles an array and returns the output
function shuffle(array) {
var counter = array.length, temp, index;
// While there are elements in the array
while (counter > 0) {
// Pick a random index
index = Math.floor(Math.random() * counter);
// Decrease counter by 1
counter--;
// And swap the last element with it
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
</script>
</head>
<body>
<ul id="order">
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment