Skip to content

Commit 5aefb10

Browse files
author
highflyer910
committed
fibonacci
1 parent ae13ebd commit 5aefb10

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

fibonacci.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
function fibonacci(num) {
2-
if (num <= 1) return num;
1+
function fibonacci_series(n)
2+
{
3+
if (n===1)
4+
{
5+
return [0, 1];
6+
}
7+
else
8+
{
9+
var s = fibonacci_series(n - 1);
10+
s.push(s[s.length - 1] + s[s.length - 2]);
11+
return s;
12+
}
13+
};
314

4-
return fibonacci(num - 1) + fibonacci(num - 2);
5-
}
6-
7-
//It's not effective but is good for tech interviews :)
15+
console.log(fibonacci_series(5));
16+

0 commit comments

Comments
 (0)