Skip to content

Instantly share code, notes, and snippets.

@mohamedhayibor
Created February 13, 2016 03:38
Show Gist options
  • Save mohamedhayibor/d9d86da6009ff15e93cb to your computer and use it in GitHub Desktop.
Save mohamedhayibor/d9d86da6009ff15e93cb to your computer and use it in GitHub Desktop.
"use strict";
// simple fisher yates implementation
const shuffle = (deck) => {
let randomizedDeck = [];
let array = deck;
while ( array.length !== 0) {
let rIndex = Math.floor(array.length * Math.random());
randomizedDeck.push(array[rIndex]);
array.splice(rIndex, 1)
}
return randomizedDeck;
};
const deck = [1,2,3,4,5,6,7];
// Testing
console.log(shuffle(deck));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment