We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c4718c1 commit 0052f94Copy full SHA for 0052f94
day18/leetcode2627.js
@@ -0,0 +1,27 @@
1
+// 2627. Debounce
2
+// URL -> https://leetcode.com/problems/debounce
3
+
4
+/**
5
+ * @param {Function} fn
6
+ * @param {number} t milliseconds
7
+ * @return {Function}
8
+ */
9
+var debounce = function (fn, t) {
10
+ let timeout;
11
+ return function (...args) {
12
+ if (timeout) {
13
+ clearTimeout(timeout);
14
+ }
15
16
+ timeout = setTimeout(() => {
17
+ fn(...args);
18
+ }, t)
19
20
+};
21
22
23
+* const log = debounce(console.log, 100);
24
+* log('Hello'); // cancelled
25
26
+* log('Hello'); // Logged at t=100ms
27
+*/
0 commit comments