Last active
August 16, 2019 20:06
-
-
Save WebRTCGame/940a2eaae46c66f13c8148da69d2d045 to your computer and use it in GitHub Desktop.
Javascript Multiple Argument Memoization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear(); | |
function mem2() { | |
let iset = {}; | |
return (fn) => { | |
return (...args) => { | |
!(args in iset) && (iset[args] = fn(...args)); | |
return iset[args]; | |
} | |
} | |
} | |
let xq = mem2()((x, y) => { | |
return x + y | |
}); | |
console.log(xq(10, 20)); | |
console.log(xq(10, 25)); | |
console.log(xq(10, 20)); | |
console.log(xq(10, 25)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment