Workshop › 15 Puzzle › Step 19 of 27
isSolved() compares every square with the solved board. A shuffle could by chance end solved, so reset shuffles
again while it is.
```js
function reset() {
tiles = solvedTiles()
do shuffle(200)
while (isSolved())
moves = 0
}
function isSolved() {
return tiles.every((t, i) => t === solvedTiles()[i])
}
```every is true only if the test is true for every item; t is the tile and i its position.do ... while (isSolved()) shuffles first, then checks, and shuffles again as long as the board is solved.reset, change shuffle(200) to do shuffle(200) and write while (isSolved()) under it.reset, leave an empty line and write isSolved. Press Run.Skills: Arrays and objects
← Which boards can be solved? Remember the slide →