Create a function that uses throttling to limit a function’s execution rate.
HardProblem Statement
Create a function that uses throttling to limit a function’s execution rate.
Sample Input
Function to throttle: logMessage Throttle interval: 1000 ms Number of calls to logMessage: 3
Sample Output
Only one output every 1000ms.
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Implement throttling to limit function execution rate
function throttle(func, limit) {
// Track the last execution time and set a timeout for additional calls
}
// Example function to throttle
function logMessage() {
// Log a message to the console
}
const throttledLog = throttle(logMessage, 1000);
throttledLog();
throttledLog();
throttledLog();
Input
Function to throttle: logMessage Throttle interval: 1000 ms Number of calls to logMessage: 3
Expected Output
Only one output every 1000ms.