Created
June 9, 2016 17:49
-
-
Save MichaelQQ/e228e2fe479f8fe4a8fcb4d90de44ecd to your computer and use it in GitHub Desktop.
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
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