This question evaluates a developer's ability to implement debounce and throttle utilities in JavaScript, testing competencies in asynchronous timing, timer management, cancellation/flush semantics, error propagation, and handling edge cases such as rapid bursts, timer drift, and re-entrancy.
Implement debounce(fn, wait, options) and throttle(fn, wait, options) in JavaScript. Support leading/trailing invocation toggles, maxWait for throttle, cancellation, and immediate flush. Ensure correctness with edge cases such as rapid bursts, timer drift, re-entrancy, and error propagation. Analyze time/space complexity and propose tests.