Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Chunk into Rows

Rendering Listsmedium

Course · Section 11: Working With Arrays · Lecture 157: The map Method

Implement `chunkRows(items, perRow)` splitting items into rows of `perRow`, for grid layouts.

Sample tests

Input: chunkRows([1,2,3,4,5], 2)
Output: [[1,2],[3,4],[5]]
Input: chunkRows([], 2)
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Mutating the source array.
  • An off-by-one in the loop bound dropping the final partial row.

Learning resources

  • React: Rendering Lists
Approach & explanation (try first)

Looping with i += perRow and slicing each window groups items into rows for grid layouts, leaving the original array intact.

Loading...
⌘/Ctrl + Enter

Run your code to see results.