title: Array pagination unknown failure
body: <p>I was resolving a HackerRank quiz, which consisted in emulating a pagination request.<br />
  The function received an array of items, the sort parameter, the sort order, the page number, and the items per page, and returns an array of names corresponding to the given page.<br />
  The items had the shape <code>[name: string, relevance: int, price: int]</code>.<br />
  The sort parameter was 0 for name, 1 for relevance, and 2 for price.<br />
  The sort order was 0 for ascending and 1 for descending.</p>
  <p>I tried the function in JavaScript and in Python, in case the default sorting function worked different and altered the results. This is my implementation in Python3.</p>
  <pre class="lang-py prettyprint-override"><code>def fetchPaginated(items, sortParameter, sortOrder, pageNum, itemsPerPage):
    sortedItems = sorted(items, key=lambda item: item[sortParameter], reverse=False if sortOrder == 0 else True)
    paginatedIdx = pageNum * itemsPerPage
    slicedItems = sortedItems[paginatedIdx:(paginatedIdx + itemsPerPage)]
    return map(lambda item: item[0], slicedItems)
  </code></pre>
  <p>Since HackerRank has hidden test cases, I don't know the inputs for the failing tests. I remember that the size of the array was in the order of the 100s and 1000s, the page number was between 0 and 2, the items per page between 1 and 20. There wasn't a pattern for the sort parameter and order (it wasn't like all the failing tests were for the sort parameter 1 or similar).</p>
  <p>Could someone indicate me if my code, or the algorithm behind it has a flaw I don't detect? Maybe a flaw that makes it fail on edge cases?</p>
  <p>EDIT:
  Link to the HackerRank question. I don't know if it's available to everyone: <a href="https://www.hackerrank.com/test/78113p6eaqn" rel="nofollow noreferrer">https://www.hackerrank.com/test/78113p6eaqn</a></p>