Skip to content

Commit e014ac6

Browse files
committed
add chapter 11
1 parent e9cd528 commit e014ac6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

chapter11/01-Recursion.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function fibonacci(num){
2+
if (num === 1 || num === 2){
3+
return 1;
4+
}
5+
if (num > 2){
6+
return fibonacci(num - 1) + fibonacci(num - 2);
7+
}
8+
}
9+
10+
function fib(num){
11+
var n1 = 1,
12+
n2 = 1,
13+
n = 1;
14+
for (var i = 3; i<=num; i++){
15+
n = n1 + n2;
16+
n1 = n2;
17+
n2 = n;
18+
}
19+
return n;
20+
}

0 commit comments

Comments
 (0)