I was looking into memoization and it simply confuses me. I've been trying to work on this example but I can't help but understand it quite clearly. This is what I came up with.
function memoize(x) {
//var x = []
check = function() {
return copycat(x,x)
}
return x;
}
function copycat(input,output) {
if (input === input || output === output) {
return ""
}
}
The goal was to input these 3 lines into the console of my browser:
function square(x) { alert("computed sq " + x); return x * x; }
msq = memoize(square)
msq(2) + msq(2) + msq(3)
It was display: computed sq 2 and then computed sq 3. It ignores the reoccurence of msq(2) but still computes the return result, which is 17. I'm really lost in how to approach this :( any help?