NovichokJS,
function saveCalls(fun) {
let callsHistory = [];
const f = (...arg) => {
callsHistory.push(arg);
return fun(...arg);
};
f.callsHistory = callsHistory;
return f
}
// example 1
function sum(firstNum, secondNum) {
return firstNum + secondNum;
}
const sumWithMemory = saveCalls(sum);
console.log(sumWithMemory(1, 2)); // ===> 3
console.log(sumWithMemory(3, 4)); // ===> 7
console.log(sumWithMemory.callsHistory); // ===> [ [1, 2], [3, 4] ]