Skip to content

Commit e1ae8eb

Browse files
committed
completed recursion.js
1 parent ca4950d commit e1ae8eb

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎recursion.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ while (n <= 10) {
1111

1212
// code here
1313

14+
const countToTen = (num = 1) => {
15+
console.log('While Looping Im Counting To', num);
16+
if (num < 10) {
17+
countToTen(num + 1);
18+
}
19+
};
20+
1421
// when you code is ready, un-comment the next line and run the file
15-
// console.log(countToTen());
22+
console.log(countToTen());
1623
/* ================ Next Problem ================= */
1724

1825
// Problem 2:
@@ -29,5 +36,11 @@ console.log(factorial(5));
2936

3037
// write the above function in a recursive way.
3138

39+
const recursiveFactorial = results => {
40+
if (results <= 1) return 1;
41+
return results * recursiveFactorial(results - 1);
42+
43+
};
44+
3245
// when your code is ready, un-comment the next line and run the file
33-
// console.log(recursiveFactorial());
46+
console.log('RecursiveFactorial is ' + recursiveFactorial(5));

0 commit comments

Comments
 (0)