Skip to content

Instantly share code, notes, and snippets.

@marcoarruda
Created April 27, 2023 21:16
Show Gist options
  • Save marcoarruda/0959ed1b3144af068ca49f6c60d96126 to your computer and use it in GitHub Desktop.
Save marcoarruda/0959ed1b3144af068ca49f6c60d96126 to your computer and use it in GitHub Desktop.
Paginator algorithm
// 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