// Write a polyfill for clearAllTimeout that tracks and clears all timeouts set
// const timeout1 = setTimeout(() => console.log("Timeout 1"), 10000);
// const timeout2 = setTimeout(() => console.log("Timeout 2"), 3000);
// const timeout3 = setTimeout(() => console.log("Timeout 3"), 4000);
// console.log("Clearing all timeouts...");
// }, 5000); // This should clear all timeouts before they execute
// we are storing original function in a varibale and overriding setTimeOut
// with custom functionality
// set original setTimeout in a variable
const originalSetTimeout = this.setTimeout;
// modify original setTimeOut
this.setTimeout = function (callback, delay, ...args) {
const timeoutId = originalSetTimeout(callback, delay, ...args);
timeouts.push(timeoutId); // Store the timeout ID
// Define clearAllTimeout to clear all timeouts
this.clearAllTimeout = function () {
timeouts.forEach((value, timeoutId) => {
this.clearTimeout(timeoutId); // Clear each timeout