FrontendInterviews.dev

Loading problem…

142. setInterval Implementation

Easy•

Implement a basic custom setInterval utility.

Requirements

Implement customSetInterval that:

  • Repeats callback execution every delay ms
  • Supports callback arguments
  • Returns a timer id
  • Treats negative delay as 0
  • Uses recursive setTimeout internally (do not use native setInterval)

Function Signature

function customSetInterval(callback, delay, ...args) {
  // return timerId
}

Constraints

  • Must repeat callback on the given interval
  • Must pass additional arguments to callback
  • Must return a timer identifier
  • Negative delay should be normalized to 0
  • Do not use native setInterval
Accepted19/25|Acceptance Rate76.0%