Skip to main content

Practice ยท 2 of 3

Offset Pagination

Write paginate(items, query) โ€” query is { limit?, offset? } (limit defaults 10, max 100; offset defaults 0). Return { results, total, next }: results is the sliced page; total is items.length; next is the next offset (as a number) when more items remain, else null. Guard against negative and non-integer inputs.

Difficulty: intermediate

Back to lesson: Practice: REST Resource Design โ€” Practice