diff --git a/problem/implement-basic-debounce_en.md b/problem/implement-basic-debounce_en.md index a74ae43d..33f3cd23 100644 --- a/problem/implement-basic-debounce_en.md +++ b/problem/implement-basic-debounce_en.md @@ -1,4 +1,26 @@ +## Very basic implementation of debouncing. -There is no solution yet. -Would you like to [contribute to the solution](https://github.com/BFEdev/BFE.dev-solutions/blob/main/problem/implement-basic-debounce_en.md)? [Contribute guideline](https://github.com/BFEdev/BFE.dev-solutions#how-to-contribute) +```javascript + +// This is a JavaScript coding problem from BFE.dev + +/** + * @param {(...args: any[]) => any} func + * @param {number} wait + * @returns {(...args: any[]) => any} + */ +function debounce(func, delay) { + let timeoutID; + + return function(...args) { +//Clearing the timeout to avoid previous function call + clearTimeout(timeoutID); +//New function is passed to the setTimeout using the JS bind method. + timeoutID = setTimeout(func.bind(this, ...args),delay); + } +} + + + +```