Created
April 27, 2023 21:16
-
-
Save marcoarruda/0959ed1b3144af068ca49f6c60d96126 to your computer and use it in GitHub Desktop.
Paginator algorithm
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
// converted to JS from this python solution: https://stackoverflow.com/a/40116188/1408053 | |
const window = 5; | |
let start = page - window | |
let end = page + window | |
if (start <= 0) { | |
end = end - start + 1 | |
start = 1 | |
} | |
if (end > totalPages) { | |
end = totalPages | |
start = Math.max(end - (window * 2) + 1, 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment