Better Explanation of the Problem!  –  [ beats 94% ]
IntuitionMy first intuition was that I needed another way to explain myself this problem, e.g. using a pizza analogy:Imagine you ordered pizza delivery, and the
# Intuition
My first intuition was that I needed another way to explain myself this problem, e.g. using a pizza analogy:


---

Imagine you ordered pizza delivery, and the estimated time of arrival is 30 minutes. However, you have the option to cancel the order before it is prepared.

Here is how it maps the problem: 
- ```fn``` execution is – pizza delivery.
- ```t``` (delay) is – 30 minutes waiting time.
- ```return cencelFn``` – call the restaurant and cancel the order.
- ```cancelTimeMs``` – the time when you **decide** to cancel, so it can be too late or not.

👉🏼 If you cancel **before** 30 minutes, the pizza is **never made**.
👉🏼 If you cancel **after** 30 minutes, the pizza is **already delivered**.

---

# Steps
1. Schedule the execution of `fn` after `t` milliseconds using `setTimeout`.
2. Store the `setTimeout` ID in a variable so we can reference it inside `cancelFn` function.
3. Return a `cancelFn` that stops the scheduled execution of `fn(...args)` by clearing `setTimeout` using its ID.


# Code
```javascript []
/**
 * @param {Function} fn
 * @param {Array} args
 * @param {number} t
 * @return {Function}
 */

const cancellable = function(fn, args, t) {

    const timerId = setTimeout(() => {
        fn(...args);
    }, t);

    const cancelFn = () => {
        clearTimeout(timerId);
    };

    return cancelFn;
};
```
['JavaScript']