Question presented to candidate: "Extend a basic throttle so the caller can independently configure whether it fires on the leading edge, the trailing edge, or both. Show me all four combinations actually behaving differently."
What a strong answer should cover:
- The base throttle mechanism (a cooldown window) stays the same; leading/trailing only control WHICH edges of that window actually invoke the function.
leading: true(the default in most implementations): the function runs immediately on the first call of a burst.trailing: true(also usually the default): if calls arrive during the cooldown, one final call runs once the cooldown expires, using the most recent arguments seen.{leading:false, trailing:false}is a real, documented edge case — a correctly-implemented throttle with BOTH disabled genuinely never invokes the function at all, which surprises people who expect it to still fire something.- Real verification: proving with real timing that all four combinations produce genuinely different call counts and timing, not just assuming the flags work from reading the option names.
Clarifying questions expected:
- "What should the default be if leading/trailing are not specified?" (a strong candidate proposes both true by default, matching common libraries like lodash and underscore)
- "For the trailing call, which call's arguments should it use — the first one dropped during cooldown, or the most recent one?" (the most recent is standard, but worth confirming)
Code / implementation expected: Yes — a full working configurable-throttle implementation, executed against all 4 leading/trailing combinations with real observed call counts and timestamps.