Skip to content

Instantly share code, notes, and snippets.

@noahzweben
Last active July 31, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahzweben/44f53e7c7ae960708444e5b55def73d0 to your computer and use it in GitHub Desktop.
Save noahzweben/44f53e7c7ae960708444e5b55def73d0 to your computer and use it in GitHub Desktop.
<1 hr JavaScript Engineering Problem for Votem

Front End Engineering Problem

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) specs

  • makeSafeInterval(func,interval) should take a function and interval (in ms) as arguments
  • makeSafeInterval(func,interval) should return a function that can be called with additional arguments
  • makeSafeInterval should execute func every interval seconds. HOWEVER, the first time func throws an error, it should stop.

Use Case Examples

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

Let us know if you have any questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment