Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Forked from therealklanni/y-memo.js
Last active August 29, 2015 14:23
Show Gist options
  • Save xgrommx/c8835bff8197a93c838e to your computer and use it in GitHub Desktop.
Save xgrommx/c8835bff8197a93c838e to your computer and use it in GitHub Desktop.
let Ym = (f, x = {}) => (...args) => {
var y = JSON.stringify(args)
return x[y] || (x[y] = f(z => Ym(f, x)(z)).apply(this, args))
}
let fib = Ym(f => n => n === 0 ? n : n === 1 ? n : f(n - 1) + f(n - 2))
console.log('fib(1000)', fib(1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment