Skip to content

Instantly share code, notes, and snippets.

@kriskornel
Created March 17, 2025 13:33
Show Gist options
  • Save kriskornel/736ec4c2f4b3edb423740b9ac90855d5 to your computer and use it in GitHub Desktop.
Save kriskornel/736ec4c2f4b3edb423740b9ac90855d5 to your computer and use it in GitHub Desktop.
pick-random-cards.js
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