if (currentPage <= visiblePagesThreshold + 1) { pagintationTriggersArray[0] = 1 const pagintationTriggers = pagintationTriggersArray.map( (paginationTrigger, index) => { return pagintationTriggersArray[0] + index } ) pagintationTriggers.push(pageCount) return pagintationTriggers } Scenario 2: The selected page number is bigger than half of the list width counting from the end of the list Similar to the previous scenario, we start with the last page and iterate through the list, this time subtracting the index from each element.
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!