Skip to content

Commit f880cd7

Browse files
committed
https://leetcode.cn/problems/debounce
1 parent e4e8bd2 commit f880cd7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,4 +2544,6 @@ https://leetcode.cn/problems/design-cancellable-function/
25442544

25452545
https://leetcode.cn/problems/group-by
25462546

2547+
https://leetcode.cn/problems/debounce
2548+
25472549
</details>

debounce/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type F = (...p: any[]) => any;
2+
3+
function debounce(fn: F, t: number): F {
4+
let timer: number | undefined;
5+
return function (...args) {
6+
clearTimeout(timer);
7+
8+
timer = setTimeout(() => {
9+
fn(...args);
10+
}, t);
11+
};
12+
}
13+
export default debounce;
14+
15+
export type { F };

0 commit comments

Comments
 (0)