Skip to content

Commit df27753

Browse files
author
Kevin Nguyen
committed
code from chapter 3 in javascript
1 parent 09a8115 commit df27753

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

03_recursion/01_countdown.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function countdown(i) {
2+
console.log(i);
3+
// base case
4+
if (i <= 0) {
5+
return;
6+
} else {
7+
countdown(i-1);
8+
}
9+
}
10+
11+
countdown(5);

03_recursion/02_greet.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function greet2(name) {
2+
console.log('how are you, ' + name + '?');
3+
}
4+
5+
function bye() {
6+
console.log('ok bye!');
7+
}
8+
9+
function greet(name) {
10+
console.log('hello, ' + name + '!');
11+
greet2(name);
12+
console.log('getting ready to say bye...');
13+
bye();
14+
}
15+
16+
greet('adit');

03_recursion/03_factorial.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function fact(x) {
2+
if (x === 1) {
3+
return 1;
4+
} else {
5+
return x * fact(x-1);
6+
}
7+
}
8+
9+
console.log(fact(5));

0 commit comments

Comments
 (0)