How do you turn a playing card into something a program can store and use? Represent each card as a simple object with a suit and a face. section 26.1
A card supports several practical operations:
- Use Sets for the available suits and faces, and a Map for face values; treat aces separately because their value can be 1 or 11. section 26.1
- Track whether each card is face up or face down by mapping the card object to a Boolean. section 26.1
- Build a 52-card deck from every suit-and-face combination, then shuffle it before use. section 26.1
- Pop cards from the deck, mark them face up, deal initial hands, and count hands while adjusting aces. section 26.1
Creating a deck
Create each card as { face, suit }, add it to a Set, and shuffle by temporarily converting the Set to an Array. The array provides indexes for swapping; the shuffled values then refill the Set. section 26.1
Listing 26.5. src/cards.js
Inspect the compact implementation that combines suits and faces into card objects and returns a shuffled deck. section 26.1



