Write a program that implements the "debounce" function to control how often a function is executed.
MediumProblem Statement
Write a program that implements the "debounce" function to control how often a function is executed.
Sample Input
Simulate a button click every 500ms, with a debounce time of 2000ms.
Sample Output
Button clicked!
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Predefined structure
function debounce(func: () => void, delay: number): () => void {
// Your logic here
}
// Simulate calls
Input
Simulate a button click every 500ms, with a debounce time of 2000ms.
Expected Output
Button clicked!