if (currentPage >= pageCount - visiblePagesThreshold + 1) { const pagintationTriggers = pagintationTriggersArray.map( (paginationTrigger, index) => { return pageCount - index } ) pagintationTriggers.reverse().unshift(1) return pagintationTriggers } Scenario 3: All other cases We know what number should be in the center of our list: the current page.
pagintationTriggersArray[0] = currentPage - visiblePagesThreshold + 1 const pagintationTriggers = pagintationTriggersArray.map( (paginationTrigger, index) => { return pagintationTriggersArray[0] + index }) pagintationTriggers.unshift(1) pagintationTriggers[pagintationTriggers.length - 1] = pageCount return pagintationTriggers That covers all of our scenarios!