Last active
March 4, 2021 10:18
-
-
Save DesignFront/6fd2a7df05bf3aad2f44b5222a0cf2f7 to your computer and use it in GitHub Desktop.
Fibonacci
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
// get the fib number: | |
function fib(n) { | |
let arr = [0,1,1]; | |
for (let i = 3; i <= n; i++) { | |
arr.push(arr[i-2] + arr[i-1]) | |
} | |
return arr[n] | |
} | |
// get first 30 numbers: | |
for (let i=0; i<30; i++) { | |
console.warn(fib(i)); | |
} | |
////////// | |
function fibonacci(num) { | |
if (num <= 1) return 1; | |
return fibonacci(num - 1) + fibonacci(num - 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment