Skip to content

Commit c8d128c

Browse files
authored
Create generating_fib.js
1 parent 7de0a50 commit c8d128c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

generating_fib.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function printGeneratingFib(N) {
2+
console.log(0);
3+
if (N < 1) {
4+
return;
5+
}
6+
console.log(1);
7+
8+
let a = 0;
9+
let b = 1;
10+
let sum = null;
11+
12+
while((a + b) <= N) {
13+
sum = a + b;
14+
console.log(sum); //Print 1,2,3,5,8...
15+
a = b;
16+
b = sum;
17+
}
18+
}

0 commit comments

Comments
 (0)