ClearTimeout Solution (with step by step explanation)
Intuition\nwe will use clearTimeout to clear timeout\n# Approach\nwe declare timerId that will hold id of setTimeout call, and then we return function in which 
# Intuition\nwe will use clearTimeout to clear timeout\n# Approach\nwe declare timerId that will hold id of setTimeout call, and then we return function in which we call clearTimeout with timerId\n# Complexity\n- Time complexity:\nO(1)\n- Space complexity:\nO(1)\n# Code\n```\ntype JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Fn = (...args: JSONValue[]) => void\n\nfunction cancellable(fn: Fn, args: JSONValue[], t: number): Function {\n    // declare timerId and call setTimeout\n    const timerId = setTimeout(() => {\n        fn(...args)\n    }, t)\n    // return function:\n\treturn () => {\n        // call clearTimeout with timerId\n        clearTimeout(timerId);\n    }\n};\n\n/**\n *  const result = []\n *\n *  const fn = (x) => x * 5\n *  const args = [2], t = 20, cancelT = 50\n *\n *  const start = performance.now() \n *\n *  const log = (...argsArr) => {\n *      const diff = Math.floor(performance.now() - start);\n *      result.push({"time": diff, "returned": fn(...argsArr)})\n *  }\n *       \n *  const cancel = cancellable(log, args, t);\n *\n *  const maxT = Math.max(t, cancelT)\n *           \n *  setTimeout(() => {\n *     cancel()\n *  }, cancelT)\n *\n *  setTimeout(() => {\n *     console.log(result) // [{"time":20,"returned":10}]\n *  }, maxT + 15)\n */\n```
['TypeScript']