Created
March 11, 2022 10:07
-
-
Save AitorAlejandro/b22d2730562cf266d315c5d5051a55c7 to your computer and use it in GitHub Desktop.
Shuffles an array of any type
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
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