Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created May 11, 2022 08:56
Show Gist options
  • Save Elijah-trillionz/e741aafee8a6f5c3b6dba377d633b6f0 to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/e741aafee8a6f5c3b6dba377d633b6f0 to your computer and use it in GitHub Desktop.
Page indexing
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