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:
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.