Created
July 19, 2017 15:56
-
-
Save johnfoderaro/6d08671d640a79d80861b86f957ee941 to your computer and use it in GitHub Desktop.
Shuffle an array's contents
This file contains hidden or 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
function shuffle(array) { | |
const shuffledArray = []; | |
for (let i = 0; shuffledArray.length !== array.length; i++) { | |
const randomIndex = Math.floor(Math.random() * array.length); | |
if (!shuffledArray.includes(array[randomIndex])) { | |
shuffledArray.push(array[randomIndex]); | |
} | |
} | |
return shuffledArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment