Octagram Labs
JavaScriptData StructuresReact
Sign in
← Back to problems

Paginate

Rendering Listsmedium

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

Implement `paginate(items, page, size)` returning the slice of `items` for the given 1-indexed `page` of `size` items.

Sample tests

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

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Off-by-one from treating the page as 0-indexed.
  • Mutating with splice instead of slicing.

Learning resources

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

slice(start, start + size) returns the items for the requested page without touching the source array. The (page - 1) offset accounts for 1-indexed pages.

Loading...
⌘/Ctrl + Enter

Run your code to see results.