Clear All Timeouts

let timers = [];

const mySetTimeout = (fn, delay) => {
  let timer = globalThis.setTimeout(fn, delay);
  timers.push(timer);
};

const myClearAllTimeout = () => {
  timers.forEach((timer) => {
    clearTimeout(timer);
  });
};

function func1() {
  console.log("func1");
}

function func2() {
  console.log("func2");
}

function func3() {
  console.log("func3");
}

mySetTimeout(func1, 2000);
mySetTimeout(func2, 3000);
mySetTimeout(func3, 1000);

myClearAllTimeout();
// No output since we cleared all setTimeout timers.