Salesforce OA Interview Problem: Implement Debounce in JavaScript

75 Views
No Comments

Implement debounce in JavaScript.

Write a function debounce that takes a function and a delay, and returns a new function that postpones invoking the original function until after the delay has elapsed since the last time the debounced function was called.

This problem asks you to implement debounce in JavaScript. The key idea is to return a closure that stores a timer id, clears any pending timeout on each call, and schedules the original function to run only after the specified delay has passed without another invocation.

END
 0