Created
January 9, 2017 22:20
-
-
Save zzarcon/f25863252278b22e79f2cebaf11bb9da 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
function fiboJs(num){ | |
var a = 1, b = 0, temp; | |
while (num >= 0){ | |
temp = a; | |
a = a + b; | |
b = temp; | |
num--; | |
} | |
return b; | |
} | |
const fiboJsRec = (num) => { | |
if (num <= 1) return 1; | |
return fiboJsRec(num - 1) + fiboJsRec(num - 2); | |
} | |
const fiboJsMemo = (num, memo) => { | |
memo = memo || {}; | |
if (memo[num]) return memo[num]; | |
if (num <= 1) return 1; | |
return memo[num] = fiboJsMemo(num - 1, memo) + fiboJsMemo(num - 2, memo); | |
} | |
module.exports = {fiboJs, fiboJsRec, fiboJsMemo}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment