Skip to content

Instantly share code, notes, and snippets.

@timstermatic
Created November 2, 2021 18:27
Show Gist options
  • Save timstermatic/b4c4e40d0cb6a18c3da689bf948f5f69 to your computer and use it in GitHub Desktop.
Save timstermatic/b4c4e40d0cb6a18c3da689bf948f5f69 to your computer and use it in GitHub Desktop.
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