Better understanding of Question + Code
Intuition \nBetter understanding of the question :\nYou have the following arguments : fn (function) , args (array of arguments) , t (time interval) which is pa
# Intuition \nBetter understanding of the question :\nYou have the following arguments : fn (function) , args (array of arguments) , t (time interval) which is passed to a function whose reference is stored in the variable "cancellable"\n\nInside the cancellable function :\nFirst, you need to call the function fn with the arguments args , just like that ,\nAfter that, you need to set a time interval, and again call the function fn with args every t time interval, store the interval ID in a variable say "id" .\n\nNow design a closure, which is a function to stop the time interval. It will call clearInterval(id).\n\nThis is all that you need to do. Do not worry about cancelTimeMs , Leetcode will deal with it itself. It will set a timeout of cancelTimeMs milliseconds, afterwhich the stop time interval function will be called.\n\nExtra Tip : Use the spread operator while calling fn with arguments args\n# Code\n```\n/**\n * @param {Function} fn\n * @param {Array} args\n * @param {number} t\n * @return {Function}\n */\nvar cancellable = function(fn, args, t) {\n    fn(...args); // first call \n    const intervalID = setInterval(()=>{fn(...args)},t); // calls after t time interval\n    return function() // closure\n    {\n        clearInterval(intervalID);\n    }\n};\n\n```
['JavaScript']