Created
June 4, 2019 01:05
-
-
Save islishude/8165902d663ef293ed60dece319df2bd 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 fib_rec(n) { | |
if (n <= 1) { | |
return 1; | |
} | |
return fib_rec(n - 1) + fib_rec(n - 2); | |
} | |
function fib_loop(n) { | |
let [pre, cur] = [0, 1]; | |
for (let i = 0; i < n; i++) { | |
[pre, cur] = [cur, pre + cur]; | |
} | |
return cur; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment