FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Use Throttle

25mins

Create a function useThrottle(fn, delay) that returns a throttled version of the provided function.

The throttled function should only be invoked at most once every delay milliseconds, even if it's called repeatedly in that time frame.

Example

const throttledLog = useThrottle(console.log, 1000); throttledLog("hello"); // logs immediately throttledLog("world"); // ignored if within 1s

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests