Skip to the solution
HardFrontendAsked in 20246 min read

Infinite scroll list simulator

3.5k views

The problem

Problem, as an interviewer would state it: "Build an infinite-scroll controller: detect when a scroll position is near the bottom and trigger a real loadMore — WITHOUT firing multiple overlapping loads while one is still in progress, and correctly stopping once there is genuinely no more data."

Examples:

Code
scroller.checkScroll({ scrollTop, scrollHeight, clientHeight }); // called on every real scroll event
// triggers loadMore ONLY once per near-bottom approach, even with many rapid scroll events

Clarifying questions expected:

  • Should rapid, repeated scroll events near the bottom (a real, common occurrence during fast scrolling) trigger MULTIPLE loadMore calls, or be correctly collapsed into one?
  • What signal indicates there is genuinely no more data left to load?
  • Should this be debounced/throttled on top of the loading-state guard, or is the guard alone sufficient?

Code / implementation expected: Yes — real, direct proof that 3 rapid near-bottom scroll events correctly trigger exactly 1 loadMore call, not 3, and that a second, later scroll correctly triggers a genuinely new load once the first settles.

  • js-coding
  • utility
  • algorithm

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, direct proof: 3 rapid near-bottom scroll events correctly collapse into exactly 1 real loadMore call, and a later scroll correctly re-triggers

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 129 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextHard

Query text highlighter

Continue