Created
March 1, 2019 07:01
-
-
Save daltonnyx/73c005b7635fe83e6f09e28ed784f8ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getInRangedValue = function(value, min, max) { | |
return value < min ? min : value > max ? max : value; | |
} | |
const pagination = function(current, visible, total) { | |
const middle = Math.ceil(visible / 2); | |
let startPage = current - middle + 1, endPage = startPage + visible; | |
startPage = getInRangedValue(startPage, 1, total - visible + 1); | |
endPage = getInRangedValue(endPage, visible, total); | |
let pages = []; | |
for(let i = startPage; i <= endPage && pages.length < visible; i++) { | |
pages.push(i); | |
} | |
return pages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment