Skip to content

Instantly share code, notes, and snippets.

@harry830622
Last active March 19, 2022 07:17
Show Gist options
  • Save harry830622/5a73c87c85385b9438062bb82527129a to your computer and use it in GitHub Desktop.
Save harry830622/5a73c87c85385b9438062bb82527129a to your computer and use it in GitHub Desktop.
js utils
// Fisher-Yates shuffle algorithm
function shuffle(arr) {
const result = [...arr];
for (let i = result.length - 1; i >= 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment