// Asked in Flipkart, intuit
// Implement a debouncing function in JavaScript that delays the execution
// of a given function until after a specified wait time has passed since the last call.
// function debounce(fn, delay) {
// const fn = debounce((message) => {
// // Simulate rapid function calls
// fn("Debounced!"); // Only this should log after 300ms
// fn("Debounced twice");
function debounce(fn, delay) {
return function (...args) {
// Set a new timeout to call the function after the delay
timeout = setTimeout(() => {
const fn = debounce((message) => {
// Simulate rapid function calls
fn("Debounced!"); // Only this should log after 300ms