mediumJS ES6+#139

Debounce with leading edge and cancel

Prompt

Implement debounce(fn, wait, options):

  1. Trailing by default: fn runs once, wait ms after the last call
  2. { leading: true }: fn fires immediately on the first call, then ignores calls until quiet
  3. The returned function exposes .cancel() to drop any pending invocation
  4. Arguments and this of the last call are forwarded to fn

This is the search-box / resize-handler primitive — write it like you'd ship it.

Hints

Solution

Your Code

15 min

Tests

Click Run to test your code