Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

'Implement ClearAllTimeouts' — what's the intended approach?

Challenges • Asked 2 months ago by Ben

Ben Commented on Jun 30, 2025:

Working on the Implement ClearAllTimeouts challenge and I’m unsure what’s expected.

I tried two approaches:

  • Brute force (browser-only): ``` const max = setTimeout(() => {}, 0); for (let i = 0; i { const id = origSetTimeout(() => { active.delete(id); fn(...args); }, delay); active.add(id); return id; };

window.clearTimeout = (id) => {
active.delete(id);
return origClearTimeout(id);
};

window.clearAllTimeouts = () => {
for (const id of active) origClearTimeout(id);
active.clear();
};
```
This seems safer and works with both numeric ids and object handles, but it does require patching.

Questions:
- Does the challenge expect the brute-force trick, or a registry-based solution?
- Should clearAll also cover setInterval, or strictly setTimeout?
- Any gotchas with Node vs browser the reviewers care about?