Skip to content

Instantly share code, notes, and snippets.

@chriswitko
Created November 24, 2014 06:18
Show Gist options
  • Save chriswitko/51e3f17fdd425f36b0ac to your computer and use it in GitHub Desktop.
Save chriswitko/51e3f17fdd425f36b0ac to your computer and use it in GitHub Desktop.
function getPaginatedItems(items, page) {
var page = page || 1,
per_page = 3,
offset = (page - 1) * per_page,
paginatedItems = _.rest(items, offset).slice(0, per_page);
return {
page: page,
per_page: per_page,
total: items.length,
total_pages: Math.ceil(items.length / per_page),
data: paginatedItems
};
}
@softmixt
Copy link

we can use _.drop instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment