JavaScript interview: Implement throttle
medium
closures
timers
Write throttle(fn, wait). The first call runs fn immediately. Calls in the next wait ms are ignored, then the next call runs again.
This is the leading-edge version (no trailing call). Pass the arguments and this through.
Your code
Runs in a Web Worker in your browser. Tests use real timers, so a run takes a second or two.