feat: function item_count() finished, working on page_count()
This commit is contained in:
parent
17de0e0f92
commit
fbf13b3f3f
34
src/codewars/kata_pagination_helper.py
Normal file
34
src/codewars/kata_pagination_helper.py
Normal file
@ -0,0 +1,34 @@
|
||||
# TODO: complete this class
|
||||
|
||||
|
||||
class PaginationHelper:
|
||||
|
||||
# The constructor takes in an array of items and an integer indicating
|
||||
# how many items fit within a single page
|
||||
def __init__(self, collection, items_per_page):
|
||||
self.collection = collection
|
||||
self.items_per_page = items_per_page
|
||||
|
||||
# returns the number of items within the entire collection
|
||||
def item_count(self):
|
||||
return len(self.collection)
|
||||
|
||||
# returns the number of pages
|
||||
def page_count(self):
|
||||
return self.items_per_page // len(self.collection)
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
def page_index(self, item_index):
|
||||
pass
|
||||
|
||||
|
||||
collection = ["a", "b", "c", "d", "e", "f"]
|
||||
helper = PaginationHelper(collection, 4)
|
||||
|
||||
print(helper.page_count())
|
||||
Loading…
x
Reference in New Issue
Block a user