diff --git a/src/codewars/kata_pagination_helper.py b/src/codewars/kata_pagination_helper.py index f041971..7a6c3fc 100644 --- a/src/codewars/kata_pagination_helper.py +++ b/src/codewars/kata_pagination_helper.py @@ -15,12 +15,22 @@ class PaginationHelper: # returns the number of pages def page_count(self): - return self.items_per_page // len(self.collection) + return int(len(self.collection) / self.items_per_page) + ( + len(self.collection) % self.items_per_page > 0 + ) # returns the number of items on the given page. page_index is zero based # this method should return -1 for page_index values that are out of range def page_item_count(self, page_index): - pass + if page_index < 0 or self.page_count() - 1 < page_index: + return -1 + + if page_index == 0: + return len(self.collection[: self.items_per_page]) + + return self.collection[ + self.items_per_page * page_index : self.items_per_page * page_index * 2 + ] # determines what page an item at the given index is on. Zero based indexes. # this method should return -1 for item_index values that are out of range @@ -28,7 +38,8 @@ class PaginationHelper: pass -collection = ["a", "b", "c", "d", "e", "f"] +collection = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] helper = PaginationHelper(collection, 4) print(helper.page_count()) +print(helper.page_item_count(2))