Skip to content

Instantly share code, notes, and snippets.

@johnfoderaro
Created July 19, 2017 15:56
Show Gist options
  • Save johnfoderaro/6d08671d640a79d80861b86f957ee941 to your computer and use it in GitHub Desktop.
Save johnfoderaro/6d08671d640a79d80861b86f957ee941 to your computer and use it in GitHub Desktop.
Shuffle an array's contents
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