Ad
  • Custom User Avatar

    pageIndex takes an item index and returns the page that it belongs on

    Because 0 is the item index, not the item itself.

  • Custom User Avatar

    Your code is failing these sample tests:

    	it ('empty collection', () => {
    		const empty = new PaginationHelper([], 10);
    
    		doTest(empty, 'pageCount', 0);
    		doTest(empty, 'itemCount', 0);
    		doTest(empty, 'pageIndex', -1, 0);
    		doTest(empty, 'pageItemCount', -1, 0);
    	});
    

    The collection is empty, so, there are no pages and no items, pageIndex should return -1 because there were no pages and pageItemCount from page 0 should also return -1 because it's an invalid page.

    Your code also have problems with the previous tests, it fails to return 0 for item 3 with pageIndex method. Not a kata issue.

  • Custom User Avatar

    I don't think it's an issue:

    The types of values contained within the collection/array are not relevant.

    It means it can be anything. Read the post below yours.

  • Custom User Avatar
  • Custom User Avatar

    OP solved the task, closing

  • Custom User Avatar

    This kata helps force people to reevaluate how many passes their code does on the list in question. If you have nested loops, you'll likely hit timeouts for the lists with 10,000,000 elements, since even the fastest computers can't parse 10 million ^ 2 elements in a reasonable timeframe.

    I suggest looking up "memoization" :)

  • Default User Avatar

    you are possibly printing a lot. if so, silence the print statements and try again

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    A bit of thought shortcut on my part, what I meant is that if you understand what this kata is about answer to your question is trivial, but without you stating what you know and what you don't, there's no way to tell what explanation you expect.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Let's narrow it down, what part of the task exactly you don't understand?