6 kyu
Implement Pagination
104user4850992
Description:
Pagination is about dividing up results into pages with a fixed number of items on each page, your task is to write a generic pagination class that manages pagination for any class implementing IEnumerable<T>
The class should take in the IEnumerable<T>
to manage in the constructor and must have the following properties:
IEnumerable<T> Items // gets the items for the current page index
int CurrentPage // gets/sets the current page index, starting at 1
int ItemsPerPage // gets/sets the number of items to return on each page, default 10 items
int Total // gets the total number of items in the source
int TotalPages // gets total number of pages
- If CurrentPage is set to <= 0 it should default back to page 1.
- If CurrentPage is set to > TotalPages Items should be empty (not null).
- If ItemsPerPage is set to <= 0 it should default back to 10 items.
- Properties listed as only gettable should not be settable.
- Settable properties can be set in any order.
For example:
var pagination = new Pagination(new List<int>() {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23});
var first = pagination.Items.ToList(); // first contains the list 1,2,3,4,5,6,7,8,9,10
pagination.CurrentPage = 2;
var second = pagination.Items.ToList(); // second contains the list 11,12,13,14,15,16,17,18,19,20
pagination.CurrentPage = 3;
var last = pagination.Items.ToList(); // last contains the list 21,22,23
int total = pagination.Total; // total is set to 23
int pages = pagination.TotalPages; // pages is set to 3
Fundamentals
Similar Kata:
Stats:
Created | Jan 9, 2017 |
Published | Jan 9, 2017 |
Warriors Trained | 288 |
Total Skips | 16 |
Total Code Submissions | 807 |
Total Times Completed | 104 |
C# Completions | 104 |
Total Stars | 13 |
% of votes with a positive feedback rating | 99% of 44 |
Total "Very Satisfied" Votes | 43 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |