Skip to content

Latest commit

 

History

History
23 lines (16 loc) · 2.06 KB

File metadata and controls

23 lines (16 loc) · 2.06 KB

Debounce hard #javascript #closure

by Pawan Kumar @jsartisan

Take the Challenge

Implement a simple debounce function in JavaScript. The function should take another function as its argument and return a new function that delays invoking the original function until after a specified time has elapsed since the last time the new function was invoked. Ensure that the debounced function is not called more than once within the specified time interval.

Example

function originalFunction() {
  console.log("Function invoked!");
}

const debouncedFunction = debounce(originalFunction, 500);

// The original function should be invoked 
//only once after 500 milliseconds
debouncedFunction(); // No immediate output
debouncedFunction(); // No immediate output

// Wait for 500 milliseconds
// Output: "Function invoked!"

Back Share your Solutions Check out Solutions