Skip to content

Instantly share code, notes, and snippets.

@WebRTCGame
Last active August 16, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebRTCGame/940a2eaae46c66f13c8148da69d2d045 to your computer and use it in GitHub Desktop.
Save WebRTCGame/940a2eaae46c66f13c8148da69d2d045 to your computer and use it in GitHub Desktop.
Javascript Multiple Argument Memoization
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