Skip to content

Commit

Permalink
https://leetcode.cn/problems/debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Apr 26, 2023
1 parent e4e8bd2 commit f880cd7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2544,4 +2544,6 @@ https://leetcode.cn/problems/design-cancellable-function/

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

https://leetcode.cn/problems/debounce

</details>
15 changes: 15 additions & 0 deletions debounce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type F = (...p: any[]) => any;

function debounce(fn: F, t: number): F {
let timer: number | undefined;
return function (...args) {
clearTimeout(timer);

timer = setTimeout(() => {
fn(...args);
}, t);
};
}
export default debounce;

export type { F };

0 comments on commit f880cd7

Please sign in to comment.