Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created March 11, 2022 10:07
Show Gist options
  • Save AitorAlejandro/b22d2730562cf266d315c5d5051a55c7 to your computer and use it in GitHub Desktop.
Save AitorAlejandro/b22d2730562cf266d315c5d5051a55c7 to your computer and use it in GitHub Desktop.
Shuffles an array of any type
const shuffleArray = <T>(arr: T[]): T[] => arr.sort(() => Math.random() - 0.5);
shuffleArray(<number[]>[1, 2, 3, 4, 5]); // -> [ 4, 5, 2, 1, 3 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment