function pickRandom(array) { return array[Math.floor(Math.random() * array.length)]; } const colors = [ { color: "black", emoji: "♣" }, { color: "black", emoji: "♠" }, { color: "red", emoji: "♥" }, { color: "red", emoji: "♦" }, ]; const numbers = "23456789JDAK"; const used_cards = []; function* getCardGen() { while (true) { const color = pickRandom(colors); const number = pickRandom(numbers); const card = { ...color, number }; if (used_cards.includes(getEmoji(card))) { continue; } used_cards.push(getEmoji(card)); yield card; } } const cardGen = getCardGen(); function getCard() { return cardGen.next().value; } function getEmoji(card) { return /* HTML */ ` ${card.number}${card.emoji} `; } module.exports = { getCard, getEmoji };