Write a function debounce(fn, delay) that returns a new function. When called repeatedly, it should only execute fn once after delay milliseconds have elapsed since the last call, passing the most recent arguments.
function debounce(fn, delay) {
// Your code here
}
Rules:
- Must reset the timer on each invocation
- Must preserve arguments passed to the debounced function
- Plain JavaScript only, no external libraries
Post your solution as a reply. Answer goes up in about a day.