Created
November 24, 2014 06:18
-
-
Save chriswitko/51e3f17fdd425f36b0ac to your computer and use it in GitHub Desktop.
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
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 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it is lodash 1.* version but now lodash is 4.* ,the _.rest parameter change.Use with caution.