Ad
  • Custom User Avatar
  • Custom User Avatar

    sorry, it's 7. You're correct, I thought that the second param is 5.
    Thanks for your suggestions! I will update kata.

  • Custom User Avatar

    The second number passed in is 7. Why would numberOfPagesToDisplay be passed in at all if it were always the same number?

  • Custom User Avatar

    Already fixed, thx!

  • Custom User Avatar

    in the second example, result has to be:
    getPages(2, 7, 9) == [1, 2, 3, 4, 5], because numberOfPagesToDisplay = 5.
    Let's imagine that it's pagination on web-site. So to be user-friendly, pagination has always contains the same numberOfPagesToDisplay, in this case it's always 5.

  • Custom User Avatar

    Randomly generated tests would be a great addition to this kata.

    Also, the description should be more explicit and clear on how things should work. eg:

    We're writing a search results page, but need to add pagination. We need you to write a function getPages(currentPage, numberOfPagesToDisplay, totalNumberOfPages) which returns an array of the page numbers to display.

    Some things to bear in mind:

    • The numberOfPagesToDisplay value will always be odd.
    • There will always be at least enough totalPages to fill the numberOfPagesToDisplay.
    • Where possible, keep the currentPage in the centre of the page numbers array. If there are not enough pages available to centre the currentPage, just fill out the sides with as many page numbers as possible.

    eg.

    getPages(7,             5,                        100)
    //       ^ currentPage  ^ numberOfPagesToDisplay  ^ totalPages
    //        v currentPage
    == [5, 6, 7, 8, 9]
    
    getPages(2,             7,                        9)
    //       ^ currentPage  ^ numberOfPagesToDisplay  ^ totalPages
    // 1 page available before `2`
    // 7 pages available after `2`
    //     v currentPage becomes off-centre
    == [1, 2, 3, 4, 5, 6, 7]
    
  • Custom User Avatar
  • Custom User Avatar

    Hahahahaha. Whoops, well it is early, my brain isnt in gear :-) I meant the DeepEquals one :-)

  • Custom User Avatar

    Random tests?

    More informative descriptions?

  • Custom User Avatar

    Nonono, not assertEquals for arrays :P

    Should be using assertSimilar or even better, assertDeepEquals.

  • Custom User Avatar

    Should be Test.assertEquals(getPages(7, 5, 100), [5, 6, 7, 8, 9]); :-)

  • Custom User Avatar

    To test whether arrays match use either Test.assertSimilar() or even better Test.assertDeepEquals().

  • Custom User Avatar

    There appears to be something wrong with the testing. It's accepting any solution. Also, random tests are strongly suggested.

  • Custom User Avatar
  • Custom User Avatar

    Cool task! EcmaScript2015 helped me to complete thistricky task easy