Skip to content

Instantly share code, notes, and snippets.

@MichaelQQ
Last active June 9, 2016 17:32
Show Gist options
  • Save MichaelQQ/ee0eb99e13a09d8d2c94b76af9f887e2 to your computer and use it in GitHub Desktop.
Save MichaelQQ/ee0eb99e13a09d8d2c94b76af9f887e2 to your computer and use it in GitHub Desktop.
// a function to create realFib function
const makeMemoFib = (f, m = {}) => {
const memoFib = (n) => {
if (m[n]) {
return m[n]
}
const fib = f(memoFib);
m[n] = fib(n);
return m[n];
};
return memoFib;
};
// simplify
const makeMemoFib = (f, m = {}) => {
const memoFib = (n) => {
if (m[n]) {
return m[n]
}
m[n] = f(memoFib)(n);
return m[n];
};
return memoFib;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment