Last active
March 19, 2022 07:17
-
-
Save harry830622/5a73c87c85385b9438062bb82527129a to your computer and use it in GitHub Desktop.
js utils
This file contains 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
// 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