Created
June 21, 2022 16:29
-
-
Save frmichetti/1998019423940257c41812e6af78e015 to your computer and use it in GitHub Desktop.
Logica do Controller de Paginação (Paginas a avançar e voltar)
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 backPages = (page:number,limit:number) => { | |
const pages = [] | |
for(let x = page ; x > 0; x--){ | |
if (x == page) continue; | |
if (pages.length == limit) continue; | |
pages.push(x) | |
} | |
return pages; | |
} | |
const frontPages = (page:number,limit:number,maxPages:number) => { | |
const pages = [] | |
for(let x = page ; x <= maxPages; x++){ | |
if (x == page) continue; | |
if (pages.length == limit) continue; | |
pages.push(x) | |
} | |
return pages; | |
} | |
const currentPage = 40 | |
const limitPerPage = 10 | |
const maxPages = 100 | |
console.log("Back Pages", backPages(currentPage, limitPerPage)); | |
console.log("Front Pages", frontPages(currentPage,limitPerPage,maxPages)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment