Find and fix the bug: pagination

A code exercise of about 15 minutes: read the statement, solve «Find and fix the bug: pagination» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

A customer report: “On page 1 I don't see the first products, sometimes the same product shows on two pages and the last one never appears”. paginate(items, page, pageSize) must return { items, page, totalPages, hasNext }: pages start at 1; totalPages is at least 1 (an empty list has one empty page); a page below 1 is treated as 1 and one above totalPages as the last one. The code has several bugs: find and fix them. In the explanation, write the bug report for one of them as you would in Jira: steps, expected result and actual result.