Skip to content

Commit 69d5128

Browse files
committed
Simple examples
1 parent eba53f0 commit 69d5128

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

JavaScript/1-recursion.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const getMaxCallStackSize = i => {
4+
try {
5+
return getMaxCallStackSize(++i);
6+
} catch (e) {
7+
return i;
8+
}
9+
};
10+
11+
console.log(getMaxCallStackSize(0));

JavaScript/2-indirect.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
function f(x) {
4+
return g(x);
5+
}
6+
7+
function g(x) {
8+
return f(x);
9+
}
10+
11+
console.log(f(0));

JavaScript/3-pow.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const pow = (base, power) => {
4+
if (power === 1) return base;
5+
else return pow(base, power - 1) * base;
6+
};
7+
8+
console.log(pow(2, 3));

JavaScript/4-factorial.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const factorial = n => {
4+
if (n === 0) return 1;
5+
else return n * factorial(n - 1);
6+
};
7+
8+
console.log(factorial(10));

JavaScript/5-fibonacci.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const fibonacci = n => (n <= 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2));
4+
5+
console.log(fibonacci(10));

0 commit comments

Comments
 (0)