Created
August 23, 2018 13:32
-
-
Save ajmeyghani/46e68e637021bb797eac4172a34d576e to your computer and use it in GitHub Desktop.
This file contains 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
var fibo = (function () { | |
var memo = {}; | |
function fi(n) { | |
if (n < 0) { return -1 } else { | |
var value = (n in memo) ? memo[n] : (!n || n === 1) ? 1 : fi(n - 1) + fi(n - 2); | |
memo[n] = value; | |
return value; | |
} | |
} | |
return fi; | |
})(); | |
view raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment