Last active
December 12, 2015 07:08
-
-
Save SamChristy/4734256 to your computer and use it in GitHub Desktop.
JavaScript implementation of Fisher-Yates shuffle (http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).
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
| function shuffle(a){ | |
| var j, temp; | |
| for(i = a.length-1; i > 1; i--){ | |
| j = Math.floor(Math.random() * (i + 1)); | |
| temp = a[i]; | |
| a[i] = a[j]; | |
| a[j] = temp; | |
| } | |
| return a; // Return to enable chaining. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment