Skip to content

Instantly share code, notes, and snippets.

@uzorjchibuzor
Created June 25, 2018 22:16
Show Gist options
  • Save uzorjchibuzor/b8e20c88865c997ce1eaaa88008da7a2 to your computer and use it in GitHub Desktop.
Save uzorjchibuzor/b8e20c88865c997ce1eaaa88008da7a2 to your computer and use it in GitHub Desktop.
Fibonacci Sequence with loop and with recursion
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
@Oluwasetemi
Copy link

The second one is niffy and soft! with recursion .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment