michaelp0730
11/17/2016 - 5:20 PM

Pagination Coding Challenge

I really like this coding challenge. An app like https://coderpad.io/ might be really helpful for phone call to watch them live and weed out candidates cheaply.

/*
Write a method that returns a string representing the state of a pagination nav bar

# rule 1: the number of pages returned should match the value of the "numVisiblePages" parameter
# rule 2: always show the first page
# rule 3: always show the last page
# rule 4: put ellipses where appropriate
# rule 5: place [] around the selected page and, if possible, center it

 */

class Solution
{
    static void Main(string[] args)
    {
        for (var i = 1; i <= 30; i++)
        {
            Console.WriteLine(paginate(i, 30, 11));
        }
    }
    
    private static string paginate(int currentPage, int totalPages, int numVisiblePages)
    {
        var numbers = string.Empty;
        
        // your code here


        return numbers;
    }
}

/*
example usage
paginate(1, 30, 11) == "[1] 2 3 4 5 6 7 8 9 10 ... 30"
paginate(5, 30, 11) == "1 2 3 4 [5] 6 7 8 9 10 ... 30"
paginate(10, 30, 11) == "1 ... 6 7 8 9 [10] 11 12 13 14 ... 30"
paginate(24, 30, 11) == "1 ... 20 21 22 23 [24] 25 26 27 28 ... 30"
paginate(30, 30, 11) == "1 ... 21 22 23 24 25 26 27 28 29 [30]"
*/