Easy way to solve (bit tricky)
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
/**
 * @param {Function} fn
 * @param {Array} args
 * @param {number} t
 * @return {Function}
 */
function cancellable(fn, args, t) {
    let timeoutId; // Store the timeout ID
    let isExecuted = false; // Track whether fn has executed

    // Schedule the execution of fn
    timeoutId = setTimeout(() => {
        isExecuted = true;
        const result = fn(...args);
        console.log({ time: t, returned: result });
    }, t);

    // Return the cancel function
    const cancelFn = () => {
        if (!isExecuted) {
            clearTimeout(timeoutId); // Cancel the scheduled fn execution
            console.log([]); // No execution, return an empty result
        }
    };

    return cancelFn;
}


```
['JavaScript']