Workshop › Blackjack › Step 3 of 22
A sorted deck is no game. The Fisher–Yates shuffle is the fair way: from the last card down, swap each card with a random card at or before it.
```js
// A new shuffled deck of 52 cards (Fisher–Yates).
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]]
}
```i goes from 51 down to 1; j is a random position from 0 to i.[deck[i], deck[j]] = [deck[j], deck[i]] swaps two cards in one line.; at the start stops JavaScript from gluing the [ line to the line before.newDeck, write the comment.newDeck, write the shuffle loop.Skills: Arrays and objects, Loops