Workshop › 15 Puzzle › Step 13 of 27
move(i) slides the tile at position i into the gap, if it is a neighbour of the gap. Sliding is just swapping the
tile and the gap in the list.
```js
// Slide the tile at position i into the gap, if it is next to the gap.
function move(i) {
const gap = tiles.indexOf(0)
if (!neighbors(gap).includes(i)) return
tiles[gap] = tiles[i]
tiles[i] = 0
}
```tiles.indexOf(0) finds the position of the gap.neighbors(gap).includes(i) asks whether i is next to the gap; ! means "not", so a far tile returns at once.Above function squareX(i), write the comment and move, and leave an empty line. Press Run.
Skills: Game states, Arrays and objects