function callTracker(fn) {
let count = 0;
function tracked(...args) { count++; return fn.apply(this, args); }
tracked.callCount = () => count;
return tracked;
}Track how many times a function has been called by wrapping it in a counter.
A decorator can track how many times a function is called.
Challenge: Implement a tracked(fn) decorator that wraps a function. The wrapper should:
The decorator should add a callCount property to the wrapper.
Example:
const fn = (x) => x * 2
const t = tracked(fn)
t(5)
t(3)
t.callCount // 2