Skip to content

Instantly share code, notes, and snippets.

@sebinsua
Created August 3, 2022 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebinsua/5deeec116caf883f101646f039e9bc2d to your computer and use it in GitHub Desktop.
Save sebinsua/5deeec116caf883f101646f039e9bc2d to your computer and use it in GitHub Desktop.
function maxCall1(fn, n) {
let count = 0;
return function withMaxCall(...args) {
if (count + 1 > n) {
return;
}
count++;
return fn(...args);
};
}
function maxCall2(fn, n) {
function withMaxCall(...args) {
withMaxCall.callCount++;
if (withMaxCall.callCount > n) {
return;
}
return fn(...args);
}
withMaxCall.callCount = 0;
return withMaxCall;
}
function helloWorld() {
console.log("hello world!");
}
const fn = maxCall2(helloWorld, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment