Created
November 2, 2021 18:27
-
-
Save timstermatic/b4c4e40d0cb6a18c3da689bf948f5f69 to your computer and use it in GitHub Desktop.
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
function createDeck() { | |
var suits = ['c','s','h','d'] | |
var values = ['A','2','3','4','5','6','7','8','9','10','j','q','k'] | |
var deck = [] | |
for(s in suits) { | |
for(v in values) { | |
deck.push(values[v] + suits[s]) | |
} | |
} | |
deck.push('j1') | |
deck.push('j2') | |
return deck | |
} | |
function shuffleDeck(array) { | |
let currentIndex = array.length, randomIndex; | |
while (currentIndex != 0) { | |
randomIndex = Math.floor(Math.random() * currentIndex); | |
currentIndex--; | |
[array[currentIndex], array[randomIndex]] = [ | |
array[randomIndex], array[currentIndex]]; | |
} | |
return array; | |
} | |
var deck = createDeck() | |
console.log(shuffleDeck(deck)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment