Workshop › 2048 › Step 11 of 26
Two equal neighbours merge into one tile of double the value, and a tile made by a merge cannot merge again in the
same move: [2, 2, 2, 2] becomes [4, 4, 0, 0], not [8, 0, 0, 0].
```js
if (tiles[i] === tiles[i + 1]) {
result.push(tiles[i] * 2)
gained += tiles[i] * 2
i++ // the next tile was used up by this merge
} else {
result.push(tiles[i])
}
```result and is added to gained.i++ inside the loop skips the next tile, which was used up by the merge. So a merged tile is never looked at again.tiles[i + 1] is undefined, never equal.In slideRow, replace result.push(tiles[i]) in the loop with the if ... else block.
Skills: Loops