Created
June 25, 2018 22:16
-
-
Save uzorjchibuzor/b8e20c88865c997ce1eaaa88008da7a2 to your computer and use it in GitHub Desktop.
Fibonacci Sequence with loop and with recursion
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 fibonacci(num) { | |
let count = 1, | |
start = 0, | |
hold, | |
seq = []; | |
while (num >= 0) { | |
hold = count; | |
count = count + start; | |
start = hold; | |
num--; | |
console.log(start); | |
seq.push(start); | |
} | |
return seq; | |
} | |
const fibb = num => { | |
if (num <= 1) return 1; | |
return fibb(num - 1) + fibb(num - 2); | |
}; | |
console.log(fibb(10)); // 89 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The second one is niffy and soft! with recursion .