Skip to content

Instantly share code, notes, and snippets.

@utimur
Created July 22, 2020 05:36
Show Gist options
  • Save utimur/2e34da5fa45ed34d73c6a40da2a6362a to your computer and use it in GitHub Desktop.
Save utimur/2e34da5fa45ed34d73c6a40da2a6362a to your computer and use it in GitHub Desktop.
Page creator
export function createPages(pages, pagesCount, currentPage) {
if(pagesCount > 10) {
if(currentPage > 5) {
for (let i = currentPage-4; i <= currentPage+5; i++) {
pages.push(i)
if(i == pagesCount) break
}
}
else {
for (let i = 1; i <= 10; i++) {
pages.push(i)
if(i == pagesCount) break
}
}
} else {
for (let i = 1; i <= pagesCount; i++) {
pages.push(i)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment