[TS] Boolean Flag, 75ms, 43.2MB
This problem requires little more than following the instructions, so we will:\n create a boolean flag willFnCall initially set to true;\n set a timeout in t mi
This problem requires little more than following the instructions, so we will:\n* create a boolean flag `willFnCall` initially set to `true`;\n* set a timeout in `t` milliseconds to call `fn` with `args`, but only if `willFnCall` is still `true`;\n* `return` a function that sets the flag to `false` when called.\n\n# Complexity\n- Time complexity: $$O(1)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```ts\nconst cancellable = (fn: Function, args: any[], t: number): Function => {\n    let willFnCall = true;\n    setTimeout(() => willFnCall && fn(...args), t);\n    return () => willFnCall = false;\n};\n```
['TypeScript']