Skip to content

Instantly share code, notes, and snippets.

View SimplyComplexable's full-sized avatar

Zack Sunderland SimplyComplexable

View GitHub Profile
@SimplyComplexable
SimplyComplexable / getActivePages.js
Created January 15, 2019 22:00
Pagination active pages resolver
const getActivePages = ({ activePage = 1, pageListLength, pages }) => {
const pageCount = pages < pageListLength ? pages : pageListLength;
const array = Array.from({ length: pageCount });
const middle = Math.ceil(pageCount / 2);
// When the page number is less than the median of the displayed pages, show first n pages
if (activePage < middle) {
return array.map((_, index) => index + 1);
}