Created
March 17, 2025 13:33
-
-
Save kriskornel/736ec4c2f4b3edb423740b9ac90855d5 to your computer and use it in GitHub Desktop.
pick-random-cards.js
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
function pickCards(take) { | |
const suits = ["()", "<>", "[]", "{}"]; | |
const ranks = [ | |
"Ace", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
"7", | |
"8", | |
"9", | |
"10", | |
"Jack", | |
"Queen", | |
"King", | |
]; | |
const deck = suits.flatMap((s) => ranks.map((n) => `${s} ${n}`)); | |
console.log(deck); | |
for (let i = deck.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[deck[i], deck[j]] = [deck[j], deck[i]]; | |
} | |
return deck.slice(0, take); | |
} | |
console.log("CARDS ", pickCards(5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment