Created
January 16, 2015 05:29
-
-
Save saschanaz/1a8cef64601f9b98de87 to your computer and use it in GitHub Desktop.
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
| class Shuffle { | |
| static shuffle<T>(array: T[]) { | |
| var turns = array.map((value, index) => index); | |
| var result: T[] = []; | |
| for (var i = 0; i < array.length; i++) { | |
| var straw = turns.splice(Math.floor(Math.random() * turns.length), 1)[0]; | |
| result.push(array[straw]); | |
| } | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment