Workshop › Klondike Solitaire › Step 8 of 40
Column 1 gets one card, column 2 two, up to seven cards in column 7, and only the last card of each is face up. What is left (24 cards) stays in the stock.
```js
const last = (pile) => pile[pile.length - 1]
// Column i gets i + 1 cards, the last one face up; the rest is the stock.
function deal() {
const deck = newDeck()
piles = { stock: [], waste: [] }
for (let f = 0; f < 4; f++) piles['f' + f] = []
for (let i = 0; i < 7; i++) {
piles['t' + i] = deck.splice(0, i + 1)
last(piles['t' + i]).up = true
}
piles.stock = deck
}
```last(pile) returns the last card: an array of length 5 has its last item at index 4.deck.splice(0, i + 1) cuts i + 1 cards off the start of the deck and returns them; the deck gets shorter.last(...).up = true turns the column's last card face up.isRed line write last.function deal() {.deal, under the foundations line, write the for loop for the columns.Skills: Arrays and objects
← Piles in one object A place for every pile →