Write a function named maxInvocations
that will be used to extend the Function.prototype
.
The function should receive a number as an argument - count
- and return a new function with the same signature and functionality as the original function.
However, this new function can only be invoked count
times. After the limit is reached, any subsequent invocations should do nothing, and have no side effects.
Function.prototype.maxInvocations = maxInvocations;
const printSum = (a, b) => {
console.log(a + b);
}
const limitedPrintSum = printSum.maxInvocations(2)
limitedPrintSum(1, 2); // Prints "3"
limitedPrintSum(11, 12); // Prints "23"
limitedPrintSum(100, 200); // Does nothing
limitedPrintSum(150, 150); // Does nothing
/**
* The first two calls to `limitedPrintSum` will run
* as expected, and print the result. However, the third
* call and any subsequent ones will be ignored because we
* have limited the function to only run twice.
*
*/