Skip to content

Instantly share code, notes, and snippets.

@okplanbo
Created August 26, 2018 10:17
Show Gist options
  • Save okplanbo/9806a0c00e4f51cf32d19f83a069ffc4 to your computer and use it in GitHub Desktop.
Save okplanbo/9806a0c00e4f51cf32d19f83a069ffc4 to your computer and use it in GitHub Desktop.
O(n) complexity, ES6 version
function shuffle(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment