SDE2🏢 Abhibus Interview Machine Coding

Deboucing - Part 1

Problem Description & Specifications

Implement a debounce function that will invoke the function once in the specified duration.

Implementation & Test Harness

Editable Monaco Runner
JavaScript Lab Sandbox
/*
Implement a debounce function that will invoke the function once in the specified duration.
*/

function debounce(fn, delay) {
    let inDebounce;
    return function () {
        if (inDebounce) {
            clearTimeout(inDebounce);
        };
        inDebounce = setTimeout(() => {
            fn.apply(this, args);
        }, delay);
    };
};
Console Output
Click "Run Code" above to execute and view output...