Created
April 24, 2018 09:48
-
-
Save NickDeckerDevs/5aafddc6af9a48862422ca3f9b4ca2b8 to your computer and use it in GitHub Desktop.
paginations class js setup
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
| // TODO: complete this object/class | |
| // The constructor takes in an array of items and a integer indicating how many | |
| // items fit within a single page | |
| function PaginationHelper(collection, itemsPerPage) { | |
| this.collection = collection; | |
| this.itemsPerPage = itemsPerPage; | |
| } | |
| // returns the number of items within the entire collection | |
| PaginationHelper.prototype.itemCount = function() { | |
| return this.collection.length; | |
| } | |
| // returns the number of pages | |
| PaginationHelper.prototype.pageCount = function() { | |
| return Math.ceil(this.itemCount() / this.itemsPerPage); | |
| } | |
| // returns the number of items on the current page. page_index is zero based. | |
| // this method should return -1 for pageIndex values that are out of range | |
| PaginationHelper.prototype.pageItemCount = function(pageIndex) { | |
| if(pageIndex < 0 || pageIndex > this.pageCount()) { | |
| return -1; | |
| } | |
| return Math.ceil(pageIndex + 1)* this.itemsPerPage; | |
| } | |
| // determines what page an item is on. Zero based indexes | |
| // this method should return -1 for itemIndex values that are out of range | |
| PaginationHelper.prototype.pageIndex = function(itemIndex) { | |
| if(itemIndex < 0 || itemIndex > this.itemCount()) { | |
| return -1; | |
| } | |
| return 'not the right answer'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment