Created
May 11, 2022 08:56
-
-
Save Elijah-trillionz/e741aafee8a6f5c3b6dba377d633b6f0 to your computer and use it in GitHub Desktop.
Page indexing
This file contains 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 filterPostsByPageIndex = (posts, pageIndex) => { | |
const postPerPage = 5; | |
// get the total posts from page 1 to current page | |
const totalPagePosts = pageIndex * postPerPage; | |
// get the total posts from page 1 to previous page | |
const prevPagePosts = totalPagePosts - postPerPage; | |
return posts.filter( | |
(post, index) => index < totalPagePosts && index >= prevPagePosts | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment