Lesson 4 of 6
Lock the piece and clear lines
When a piece lands, merge(grid, piece) writes its 1s into the grid — it's now part of the landscape.
clearLines(grid) scans bottom-up: every full row is removed (splice), an empty row is added on top (unshift), and cleared rows are counted.
grid.splice(r, 1); // remove the full row grid.unshift(emptyRow); // empty row on top cleared = cleared + 1;
🎯 Your goal
Write merge(grid, piece) that writes the piece's 1-cells into the grid, and clearLines(grid) that clears full rows (splice + unshift of a 0-row) and returns how many were cleared.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →