Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function that implements a rate limiter for a given function, limiting its execution to once every specified interval.

Hard

Problem Statement

Create a function that implements a rate limiter for a given function, limiting its execution to once every specified interval.

Sample Input

Function to be rate limited: logMessage
Rate limit interval: 1000 ms
Number of calls to logMessage: 5

Sample Output

Only one output every 1000ms.

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Implement rate limiting on a function function rateLimiter(func, limit) { // Initialize variable to track last executed time // Return a function that checks time elapsed and executes func accordingly } // Example function to limit function logMessage() { // Log a message to the console } const limitedLog = rateLimiter(logMessage, 1000); limitedLog(); limitedLog(); limitedLog();
Log in or sign up to run or submit your code.Log inSign up
Input
Function to be rate limited: logMessage
Rate limit interval: 1000 ms
Number of calls to logMessage: 5
Expected Output
Only one output every 1000ms.