Last active
June 9, 2016 17:32
-
-
Save MichaelQQ/ee0eb99e13a09d8d2c94b76af9f887e2 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
// 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