AlgoDaily Solution

1const timers = new Set();
2window.nativeSetTimeout = window.setTimeout;
3window.nativeClearTimeout = window.clearTimeout;
4
5window.clearAllTimeouts = () => {
6  for (const id of timers) {
7    clearTimeout(id);
8  }
9};
10
11window.setTimeout = (cb, time, ...args) => {
12  const cbWrapper = () => {
13    cb(...args);
14    timers.delete(id);
15  };
16  const id = nativeSetTimeout(cbWrapper, time);
17  timers.add(id);
18  return id;
19};
20
21window.clearTimeout = (id) => {
22  nativeClearTimeout(id);
23  timers.delete(id);
24};

Community Solutions

Community solutions are only available for premium users.

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.

JAVASCRIPT
OUTPUT
Results will appear here.