MediumPro challengePythonJavaScriptTypeScript
Pagination Range
AlgorithmsArrays
Implement solve(currentPage, totalPages, siblings) returning a pagination
range with ellipses, like [1, '...', 4, 5, 6, '...', 10].
Rules:
- Always include first and last page.
- Show
siblingspages on either side ofcurrentPage. - Use
'...'between non-contiguous numbers. - Never repeat numbers.
Sample tests
Test #1At start
Input: [1,5,1]
Output: [1,2,"...",5]
Test #2Middle with siblings
Input: [5,10,1]
Output: [1,"...",4,5,6,"...",10]
Test #3At end
Input: [10,10,1]
Output: [1,"...",9,10]
Test #4No ellipses needed
Input: [3,5,1]
Output: [1,2,3,4,5]
Test #5Two siblings
Input: [50,100,2]
Output: [1,"...",48,49,50,51,52,"...",100]