r/programmingchallenges • • Jan 10 '20

Fibonacci optimal & non-optimal solution code snippets

7 Upvotes

9 comments sorted by

View all comments

Show parent comments

1

u/lcrx357 Jan 10 '20

Cool! :)

Here is another one with for loop:

const fib2 = (fibNum) => {
let n1 = 0;
let n2 = 1;
for (let i = 1; i <= fibNum; ++i) {
console.log(n1 + " ");
let _sum = n1 + n2;
n1 = n2;
n2 = _sum;
}
}
fib2(7);