Hello.
I’m stuck again but now with the memoization thing.
My code is failing test 15: memoizeTransform > should not call the memoized function if the input is the same
But once again I can’t see why because as far as my understanding goes, it’s pretty clear the memoized function f is not called if you provide the same input twice because it’s only called in the body of the if statement when the input is new.
What’s going on?
Thank you.
export function memoizeTransform(f) {
const cache = {
lastInput: null,
lastResult: null
}; // for storing already computed data.
function applyFunction(a, b) {
if (cache.lastInput !== [a, b]) {
cache.lastInput = [a, b];
cache.lastResult = f(a, b);
}
return cache.lastResult;
}
return applyFunction;
}