Created
April 11, 2017 04:28
-
-
Save kelseyll/fbf1fd95a868d65270820e0fd062b417 to your computer and use it in GitHub Desktop.
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
// Run through each index and assign random number | |
for (var array=[], i = 0; i < 4; ++i) array[i] = i; | |
function shuffle(array) { | |
var tmp, current, top = array.length; | |
if(top) while(--top) { | |
current = Math.floor(Math.random() * (top + 1)); | |
tmp = array[current]; | |
array[current] = array[top]; | |
array[top] = tmp; | |
} | |
return array; | |
} | |
// Generate and print array | |
var array = shuffle(array); | |
console.log(array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment