Skip to content

Instantly share code, notes, and snippets.

@frmichetti
Created June 21, 2022 16:29
Show Gist options
  • Save frmichetti/1998019423940257c41812e6af78e015 to your computer and use it in GitHub Desktop.
Save frmichetti/1998019423940257c41812e6af78e015 to your computer and use it in GitHub Desktop.
Logica do Controller de Paginação (Paginas a avançar e voltar)
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