Created
November 1, 2013 13:03
-
-
Save TerryMooreII/7265100 to your computer and use it in GitHub Desktop.
Deck of Cards
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
var suites = ['\u2660', '\u2665', '\u2666', '\u2663']; | |
var numbers = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']; | |
var buildDeck = function(){ | |
var deck = []; | |
for (suite in suites) | |
for (number in numbers) | |
deck.push(numbers[number] + suites[suite]); | |
return deck; | |
} | |
var shuffle = function(deck){ | |
var i = deck.length, j, temp; | |
if ( i == 0 ) return; | |
while ( --i ) { | |
j = Math.floor( Math.random() * ( i + 1 ) ); | |
temp = deck[i]; | |
deck[i] = deck[j]; | |
deck[j] = temp; | |
} | |
return deck; | |
} | |
console.log(shuffle(buildDeck())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment