Skip to content

Instantly share code, notes, and snippets.

@truongluu
Created April 12, 2021 09:22
Show Gist options
  • Save truongluu/1e478724aaa0e9693c1454c00fef132b to your computer and use it in GitHub Desktop.
Save truongluu/1e478724aaa0e9693c1454c00fef132b to your computer and use it in GitHub Desktop.
Shuffle js
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment