Web Developer Kata

10 Jun 2017

I've recently started using CodeWars recently and I'm actually really excited about the little projects that they do, so I've decided to try to come up with my own kata based off of my experiance working as a web developer.

(Mostly) Even Groups

You're given a list of strings and you need to split them into N (mostly) even groups. If you can't divide them evenly, earlier groups should have more than later ones. Additionally, concatenating all of the groups should produce the original list.

Examples:

Groups(["Alabama", "Alaska", "Arizona", "Arkansas" ], 2) ->
    [
        ["Alabama", "Alaska"],
        ["Arizona", "Arkansas"]
    ]
Groups(["Alabama", "Alaska", "Arizona", "Arkansas" ], 3) ->
    [
        ["Alabama", "Alaska"],
        ["Arizona"],
        ["Arkansas"]
    ]

Pagination

Given a total number of pages, the current page, and a maximum number of links decide return the page numbers for the pages in the navigation. Follow the following rules (with priority dictated by the order of the list):

  1. If there is space available and a next page, show a link to the next page
  2. If there is space available and a previous page, show a link to the previous page
  3. If there is space available and this is not the first page, show a link to the first page
  4. If there is space available and this is not the last page, show a link to the last page
  5. As space permits, show links to the closest pages choosing to have one more link after the current page than before it if there is not an even number of spaces

Examples:

Paginate(20, 1, 5)  ->  [2, 3, 4, 5, 20]
Paginate(20, 4, 5)  ->  [1, 3, 5, 6, 20]