5 kyu

Pagination control - Showing page numbers

133 of 220brunolm
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • vadya-coder Avatar

    Add even more information about what the algorithm should be.

    As a result of the tests, I get this "error". 'Params: 3, 1, 5' 'Your pages 1....3' 'Expected pages 1..2..3'

  • chrift Avatar

    This doesn't make any sense. Where in the description does it mention that the center should be included every time?

  • mitstack Avatar

    What should be the output when I provideinput (length, currentPage, size) : (10,3,4) ?

    • If I include left side pages -4, it goes to negavtive
    • If I include right sie pages to compensate the left side values, then surpasses array length 10
  • wthit56 Avatar

    For test 3: "should return 1, 3, 4, 5, 10 for 10 pages, at page 4, with +-1 item"...

    It's telling me "expected 2 to equal 3." Which is pretty unhelpful as it doesn't say what it's even testing. Using Test.assertDeepEquals would be quicker to write, and also more self-explanatory.

    Also, you can add real comments to help the testee.

  • rickansen Avatar

    solved in 2 hours, the other hour is me spamming ctrl Z and Y coz I refactored and break something. turns out I deleted the '+ 1'

  • bigtone1284 Avatar

    I still find this example and test very confusing:

    Another example:
    
    Total pages: 36
    Current page: 1
    Items before and after: 5
    Expected [1 (always) 2,3,4,5,6 (5 before) ,7, (center) 8,9,10,11,12, (5 after) 36] (always)
    

    I don't understand where center comes from here.

    I think a clearer implementation would just be to show 5 pages before and after the current page. But if you hit either the first page or the last page, then you show the extra pages after the current page.

    So here, given that 1 is the current page, I think showing 10 pages beyond 1. The center thing just doesn't make sense to me.

  • docgunthrop Avatar

    This comment has been hidden.

  • ZozoFouchtra Avatar

    This comment has been hidden.

  • HerrWert Avatar

    Are your test results wrong, or am I misunderstanding the instructions? If your arguments are 36, 1, 5, shouldn't that yield the array [1, 2, 3, 4, 5, 6, 36], according to your instructions?

    • brunolm Avatar

      Total pages: 36 Current page: 1 Items before and after: 5

      Should return [1 (always) 2,3,4,5,6 (5 before) ,7, (center) 8,9,10,11,12, (5 after) 36] (always)

      The number of pages shown at page 1 and 7 should be the same (at page 1 you don't see just +5, you see the same number of items as if you were on page 7)

      How do you suggest I write to make it clearer? I will add this example on the description...

    • Hacker Sakana Avatar

      Should not Current Page be 7 instead of 1 in your example?

    • HerrWert Avatar

      Thanks for your reply. When I read that the current page is 1, and the items before and after are 5, that tells me that it would be (theoretically) -4, -3, -2, -1, 0 (before the 1) and then the current page 1, and then 2, 3, 4, 5, 6 (after the 1). Obviously, the values <= 0 are invalid, so they don't get included in the result.

      I don't know how you can pass "1" as the current page, and then measure the -5 and +5 from the number 7. It seems Hacker Sakana and I agree on this.

      So to answer your question, if you're not measuring the -5 and +5 off the "current page" parameter, then you must explain how we determine the "center" value. (I hope I am making this clear.)

    • brunolm Avatar

      I added a brief explanation of negative values and values over the max. Is it better now?

    • HerrWert Avatar

      OK, so it seems your description should say that the -5 and +5 are measured from the current page value if possible, but if not, then you must shift from the current page value to the closest possible "center value" that has at least -5 and +5 surrounding it.

      But I really don't think this makes a lot of sense anyway. If I'm trying to look at page 1 of a document, why would I want the display to be centered around page 7?

      If you still want to maintain this logic, you need a better way to describe the rationale behind it. Maybe like this: Always include the first and last page. Also try to include (2 * before/after value) + 1; if possible, center these page numbers on the current page. But if this doesn't yield enough pages, then shift the center value away from the current page only as much as necessary. As a native English speaker, this is the best explanation I can compose. But it's still confusing :(

      UPDATE: Just read your last post and your newest description. It's not bad! I think mine is maybe a little better.