From e4c64f36b6014909cf3278bd20fe24126adb540f Mon Sep 17 00:00:00 2001 From: Niranjan A S Date: Thu, 16 May 2024 16:44:22 +0530 Subject: [PATCH] Update implement-basic-debounce_en.md --- problem/implement-basic-debounce_en.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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); + } +} + + + +```