Generation

generate functionSat, 26 Nov 2022

masonry layout grid

const items = [1, 2, 3, 4, 5]; const itemsPerRow = 4; function masonryGrid(items, itemsPerRow) { let rows = []; let currentRow = []; for(let i = 0; i < items.length; i++) { currentRow.push(items[i]); if(i % itemsPerRow === itemsPerRow - 1 || i === items.length - 1) { rows.push(currentRow); currentRow = []; } } return rows; } masonryGrid(items, itemsPerRow)

TypeScript
Generate More

Questions about programming?Chat with your personal AI assistant