Write a function called makeSafeInterval(func,interval)
, which sets up an interval that executes func
every interval
seconds, stopping the first time func
throws an error.
makeSafeInterval(func,interval)
should take a function and interval (in ms) as argumentsmakeSafeInterval(func,interval)
should return a function that can be called with additional arguments- makeSafeInterval should execute
func
everyinterval
seconds. HOWEVER, the first time func throws an error, it should stop.
let correctFx = (a)=>console.log(a);
let correctLogInterval = makeSafeInterval(correctFx,1000);
correctLogInterval('hi'); //logs 'hi' every second
let incorrectFx = (a)=>console.lg(a) //mispelled console.log, so will throw error;
let incorrectLogInterval = makeSafeInterval(incorrectFx,1000);
incorrectLogInterval('hi'); //rather than throw an error every second, logs "stopping interval" once and stops