Skip to content

Instantly share code, notes, and snippets.

@saschanaz
Created January 16, 2015 05:29
Show Gist options
  • Select an option

  • Save saschanaz/1a8cef64601f9b98de87 to your computer and use it in GitHub Desktop.

Select an option

Save saschanaz/1a8cef64601f9b98de87 to your computer and use it in GitHub Desktop.
Shuffle
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