FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Resumable Interval

25mins

Implement a function resumableInterval(callback, delay) that creates an interval which can be paused and resumed.

The returned object should have methods:

  • start(): starts or resumes the interval.
  • pause(): pauses the interval.
  • stop(): stops the interval completely.

The interval should repeatedly invoke the callback every delay milliseconds while running.

Example

const interval = resumableInterval(() => console.log('tick'), 1000); interval.start(); // starts logging 'tick' every 1s setTimeout(() => interval.pause(), 3500); // pauses after ~3 ticks setTimeout(() => interval.start(), 5000); // resumes interval setTimeout(() => interval.stop(), 9000); // stops interval

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests