Last active
June 20, 2017 22:33
-
-
Save wdiasvargas/0611513134808a994c1ef9e32b9de963 to your computer and use it in GitHub Desktop.
fibonacci_memoization_oneliner
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
/** | |
* Created by William on 20/06/2017. | |
*/ | |
import fibonacci from './fibonacci'; | |
export default (n = 0) => (m = {}) => (m[n]) ? (m[n]) : (n <= 1) ? (n) :(m[n]) = ((fibonacci(n-1)(m)) + (fibonacci(n-2)(m))); | |
console.info(fibonacci(7)()) | |
// function fibonacci(num, memo) { | |
// memo = memo || {}; | |
// | |
// if (memo[num]) return memo[num]; | |
// if (num <= 1) return 1; | |
// | |
// return memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo); | |
// | |
// | |
// } | |
//https://gist.github.com/zzarcon/d4bea4fb85f317fe8fc1#file-fibonacci_memoization-js | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment