Workshop › Tetris-style Blocks › Step 23 of 32
A full row disappears and everything above falls down. Because the board is a list of rows, this is two list operations: keep the rows that still have a gap, and put new empty rows on top.
```js
function clearLines() {
const kept = board.filter((row) => row.some((cell) => cell === 0))
const cleared = ROWS - kept.length
if (cleared === 0) return
board = [...Array.from({ length: cleared }, emptyRow), ...kept]
}
clearLines()
```row.some((cell) => cell === 0) asks "is there at least one empty cell in this row?".board.filter(...) keeps only the rows where that is true: the rows that are not full, in their old order.ROWS - kept.length is how many rows were full.[...a, ...b] spreads two lists into one: cleared new empty rows first, then the kept rows. 20 rows again.lock clears lines after writing the piece and before the next one appears.clearLines above function lock() {.lock, call clearLines() above spawn().Skills: Arrays and objects
← Play again Points for lines →