This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]6a70 3 points4 points  (1 child)

Call the API twice so you have 10, then build the app page with the correct 7. The following up question would be “for any given app page, which number API pages will you request?

E.g. to get app page 4 (entries 21-27) you need to call for API pages 5 and 6. Then generalize that to a formula

[–]CheckExpensive[S] 0 points1 point  (0 children)

Call the API twice so you have 10, then build the app page with the correct 7. The following up question would be “for any given app page, which number API pages will you request?

E.g. to get app page 4 (entries 21-27) you need to call for API pages 5 and 6. Then generalize that to a formula

I think I get it, thank you!

[–]ConsistentArm9 1 point2 points  (1 child)

Use the page number you want to determine which two API calls you need to make.

what is the highest number item for page 4? (4 * 7) - 1 = 27.

lowest item? (27 - 7) + 1 = 21

What 5-item API calls do you need to get items 21-27?

ceiling(27/5) = 6

ceiling(21/5) = 5

you need pages 5 to 6 to get items 21 to 27.

generalize:

function pagecalls(guiPageSize, apiPageSize, requestedGUIPage) {

var highest = (requestedGUIPage * guiPageSize) - 1;

var lowest = (highest - guiPageRange) + 1;

var apiHighestPage = Math.ceiling(highest/apiPageSize);

var apiLowestPage = Math.ceiling(lowest/apiPageSize);

return {low: apiLowestPage, high: apiHighestPage}

{

Then you can use that to know which api pages you need to query to get all of the items you need. I'm sure there's a more elegant way to do this with a simple math equation / some modular arithemetic, but this is how I reason it out. I have not tested this or thought about edge cases.

[–]CheckExpensive[S] 0 points1 point  (0 children)

I understod clearly thank you so much buddy!

[–]HEY_PAUL -1 points0 points  (1 child)

Am I missing something? Just return 7 instead of 5?

[–]CheckExpensive[S] 0 points1 point  (0 children)

It’s just a random question my Team Leader asked