Intern — Middle
Debounce function for delayed call
livecode
Task condition
It is necessary to create a debounce function that takes a target function fn and a delay duration timeout (in milliseconds). The function should return a new wrapper that will call fn only after the specified interval has passed since the last call to it. If the wrapper is called again before the timeout expires, the current timer is canceled and restarted.
function debounce(fn, timeout) {
// Implementation
}
const fn = debounce(() => console.log('fn'), 300);
fn();
fn();
fn();
// Expected output: 'fn' (once, 300 ms after the last call)