Created
February 23, 2022 08:09
-
-
Save nullxx/7c7ee44bf115231affd932f187728bc1 to your computer and use it in GitHub Desktop.
Paginate reverse order
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 requestedPage = 5; | |
const page = Math.max(1, requestedPage + 1); | |
console.log('Requested page', page); | |
const totalNotis = 20; | |
const paginate = 3; | |
const skip = Math.max(0, totalNotis - page * paginate); | |
console.log('Skip', skip); | |
let target = Math.max(0, (totalNotis - page*paginate) + paginate) | |
const limit = target - skip | |
console.log('limit', limit); | |
console.log(`Page ${page}:`, 'From', skip, 'to', target); | |
const nextTarget = (totalNotis - (page+1)*paginate) + paginate | |
const hasNextPage = nextTarget > 0; | |
console.log('hasNextPage', hasNextPage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment