Skip to content

Instantly share code, notes, and snippets.

@MichaelQQ
Created June 9, 2016 17:49
Show Gist options
  • Save MichaelQQ/e228e2fe479f8fe4a8fcb4d90de44ecd to your computer and use it in GitHub Desktop.
Save MichaelQQ/e228e2fe479f8fe4a8fcb4d90de44ecd to your computer and use it in GitHub Desktop.
const makeMemoFib = (f, m = {}) => (n) => {
if (m[n]) {
return m[n]
}
m[n] = f(makeMemoFib(f, m))(n);
return m[n];
};
// simplify again
const makeMemoFib = (f, m = {}) => (n) => {
return m[n] ? m[n] : (m[n] = f(makeMemoFib(f, m))(n));
};
// one more
const makeMemoFib = (f, m = {}) => (n) => m[n] ? m[n] : (m[n] = f(makeMemoFib(f, m))(n));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment