Created
September 13, 2013 03:37
-
-
Save vasco3/6546567 to your computer and use it in GitHub Desktop.
shuffle a deck of cards
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
var deck = []; | |
function createDeck(cardQty){ | |
for(var i = 0; i < cardQty; i++){ | |
deck[i] = i + 1; | |
} | |
} | |
function shuffle(deck){ | |
var deckShuffled = []; | |
for (var i = 0; i < deck.length ; i++) { | |
function changeDecks(){ | |
randomize(); | |
if(deck[r] !== undefined ){ | |
deckShuffled[i] = deck[r]; console.log(i + " " + r); | |
delete deck[r]; | |
} | |
else{ | |
changeDecks(); | |
} | |
} | |
function randomize(){ | |
r = Math.floor( Math.random() * deck.length ); | |
} | |
randomize(); | |
changeDecks(); | |
}; | |
return deckShuffled; | |
} | |
createDeck(10); | |
shuffle(deck); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment