Workshop › Klondike Solitaire › Step 15 of 40
When the stock is empty, turning it over again takes the whole waste back, face down, so you can go through it again. It must come back in the same order, as with real cards: the waste is flipped over like a real pile.
```js
} else {
// An empty stock takes the waste back, face down, in the same order as before.
piles.stock = piles.waste.reverse().map((card) => ({ ...card, up: false }))
piles.waste = []
}
```reverse() flips the order of an array: the first card turned over ends up last in the new stock, so it comes out first
again.map makes a new array by changing every item; { ...card, up: false } is a copy of the card with up set to false.
The object is in parentheses so the arrow function returns it.In flipStock, after the if block's closing }, add the else block.
Skills: Arrays and objects
← Space turns a card What is under the pointer? →