Created
February 23, 2018 13:24
-
-
Save mattcodez/bd64a52a223d2942a8a003bf8b15fc35 to your computer and use it in GitHub Desktop.
Fibonacci
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
function fib_i(num) { | |
console.log(`Series of ${num}`); | |
let num2 = 0, num1 = 1; | |
for (let i = 0; i < num; i++) { | |
console.log(num1); | |
const next = num2 + num1; | |
num2 = num1; | |
num1 = next; | |
} | |
} |
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
function fib_r(num) { | |
if (num <= 1) { | |
return 1; | |
} | |
let num2 = fib_r(num - 2), | |
num1 = fib_r(num - 1); | |
let next = num1 + num2; | |
return next; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment