call(back)
Frontendeasy

Implement debounce()

Implement debounce(fn, wait): return a wrapped function that delays invoking fn until wait milliseconds have passed since the last call. Support a cancel() method that drops any pending invocation, and be ready to explain how debounce differs from throttle and when a leading-edge option matters.

The grader replays timed call scripts against your implementation on a virtual clock. Each case's input is the wait plus a script of [ms, action, ...args] steps; the expected output lists every fire as {at, args}. Forward arguments faithfully.

Asked at