Skip to content

Instantly share code, notes, and snippets.

@TrejGun
Created August 4, 2021 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrejGun/fe9729137d0b3b134560b4b8bec974f4 to your computer and use it in GitHub Desktop.
Save TrejGun/fe9729137d0b3b134560b4b8bec974f4 to your computer and use it in GitHub Desktop.
fisherYates
export const fisherYates = <T>(array: Array<T>): Array<T> => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment