Modify the code for running the problem to better understand what's happening
Intuition\n Describe your first thoughts on how to solve this problem. \n\nWithin the cancellable function do 2 things:\n * 1. start a function f1 that gets exe
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nWithin the cancellable function do 2 things:\n * 1. start a function f1 that gets executed every t seconds\n * 2. return a function f2. When called, the function f2 must cancel the function f1.\n * We can achieve #1 using the setInterval function.\n * We can achieve #2 using the cancelInterval function.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* Slightly adjust the code given for running the problem in order to get a better idea of what\'s happening. After running the code it becomes clearer how things work.\n\n```\nvar cancellable = function(f1, args, t) {\n\n    f1(...args); // call f1\n    let timer = setInterval(() => {\n        console.log("still running");\n        f1(...args);\n    }, t);\n\n    let f2 = (msg) => {\n        console.log(msg)\n        clearInterval(timer);\n    }\n\n    return f2;\n};\n\nconst result = [];\nconst fn = (x) => x * 2;\nconst args = [4], t = 1000, cancelTimeMs = 10000;\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   /**\n    * This is how f1 gets called, and f2 gets returned.\n    * After this line executes, the function will execute\n    * every t seconds and we will have f2 returned to us\n    * into \'cancel\'. We can then stop f1 when we\'d like by \n    * calling \'cancel\'.\n    */\n   const cancel = cancellable(log, args, t); \n \n   /**\n    * In the line below we\'re stating "after \'cancelTimeMs\' has\n    * elapsed, stop f1 from continuing to run". Note: An arrow function \n    * is being used, in order to avoid immediately calling cancel.\n    */\n   setTimeout(() => cancel(\'call made to stop execution.\'), cancelTimeMs);\n    \n   setTimeout(() => {\n       console.log(result); \n   }, cancelTimeMs + t + 15)    \n```\n# Code\n```javascript []\n/**\n * @param {Function} fn\n * @param {Array} args\n * @param {number} t\n * @return {Function}\n */\nvar cancellable = function(fn, args, t) {\n\n    fn(...args);\n    const intervalFn = setInterval(() => fn(...args), t);\n\n    return function(cancelTimeMs) {\n\n        clearInterval(intervalFn);\n    }\n    \n};\n\n/**\n *  const result = [];\n *\n *  const fn = (x) => x * 2;\n *  const args = [4], t = 35, cancelTimeMs = 190;\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 *  setTimeout(cancel, cancelTimeMs);\n *   \n *  setTimeout(() => {\n *      console.log(result); // [\n *                           //     {"time":0,"returned":8},\n *                           //     {"time":35,"returned":8},\n *                           //     {"time":70,"returned":8},\n *                           //     {"time":105,"returned":8},\n *                           //     {"time":140,"returned":8},\n *                           //     {"time":175,"returned":8}\n *                           // ]\n *  }, cancelTimeMs + t + 15)    \n */\n```
['JavaScript']