Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
My JavaScript code is failing, but i can't understanding the reason.
My code:
// 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.collection.length / 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) {
return this.collection.length >= this.itemsPerPage * (pageIndex+1) && pageIndex >= 0 ? this.itemsPerPage : this.pageCount() >= (pageIndex+1) && pageIndex >= 0 ? this.itemsPerPage * (pageIndex+1) - this.collection.length : -1;
}
// 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) {
return itemIndex <= this.collection.length && itemIndex > 0 ? Math.ceil(itemIndex / this.itemsPerPage) : (itemIndex == 0 ? (this.collection.length > 0 ? 0 : -1) : -1);
}
Can someone explain me why?
I think it's correct.