Timeout Cancellation
IntuitionTo solve this problem, we need a function that can execute another function after a specified delay and can also cancel the execution if needed. This i
# Intuition
To solve this problem, we need a function that can execute another function after a specified delay and can also cancel the execution if needed. This is useful for scenarios where you might want to schedule a function to run but also have the ability to cancel it before it runs.

# Approach
1. Define the cancellable function: This function should take another function fn, an array of arguments args, and a delay time t in milliseconds.
2. Set a timeout: Use setTimeout to schedule the execution of fn with the provided args after t milliseconds.
3. Return a cancel function: Provide a way to cancel the scheduled execution by calling clearTimeout on the created timeout.

# Complexity
- Time complexity:
    . $$O(1)$$
The time complexity is constant because setting and clearing a timeout are both constant-time operations.

- Space complexity:
    .$$O(1)$$
The space complexity is also constant because we are only storing a fixed number of variables.

# Code
```javascript []
/**
 * @param {Function} fn
 * @param {Array} args
 * @param {number} t
 * @return {Function}
 */
var cancellable = function(fn, args, t) {
    const cancelFn = function(){
        clearTimeout(timer);
    }
    const timer = setTimeout(() => {
        fn(...args);
    } , t )
    return cancelFn;
};


   const result = [];
 
   const fn = (x) => x * 5;
   const args = [2], t = 20, cancelTimeMs = 50;
 
   const start = performance.now();
 
   const log = (...argsArr) => {
       const diff = Math.floor(performance.now() - start);
       result.push({"time": diff, "returned": fn(...argsArr)});
   }
        
   const cancel = cancellable(log, args, t);
 
   const maxT = Math.max(t, cancelTimeMs);
            
   setTimeout(cancel, cancelTimeMs);
 
   setTimeout(() => {
       console.log(result); // [{"time":20,"returned":10}]
   }, maxT + 15)
 
```
['JavaScript']