In my system, there is a square function that looks like this:
function square(a) {
console.log(a);
return a * a;
}
This square function gets called multiple times throughout the program's lifecycle. For example:
square(5);
square(1);
square(2);
square(3);
The challenge now is to track the number of times the square function is called at any given moment using square.count
, which should return 4
.
The solution needs to not only work for the square function but also be adaptable and applicable to other functions in the system. For instance, if there is a power(a,n)
function, it should also be possible to retrieve the call count for power function with something like power.count
.