Implement a function limit(fn, n) that restricts the execution of a given function to at most n times.
The function should:
fn.fn only up to n times.n calls, subsequent invocations should return undefined without executing fn.Examples
function greet(name) { return 'Hello ' + name; } const limitedGreet = limit(greet, 2); limitedGreet('Alice'); // 'Hello Alice' limitedGreet('Bob'); // 'Hello Bob' limitedGreet('Carol'); // undefined
JavaScript Function
No test results yet
Click "Run" to execute tests