Skip to content

Commit 6913818

Browse files
committed
Completed problem 2 in recursion.js
1 parent 732b471 commit 6913818

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎recursion.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ while (n <= 10) {
99

1010
// write a recursive - function called countToTen that mimics the while loop above.
1111

12+
// code here
13+
1214
function countToTen(count) {
1315
if (count > 10) return;
1416
console.log(count);
1517
countToTen(++count);
1618
}
1719

18-
// code here
19-
2020
// when you code is ready, un-comment the next line and run the file
21-
// console.log(countToTen());
21+
countToTen(1);
2222
/* ================ Next Problem ================= */
2323

2424
// Problem 2:
@@ -35,5 +35,10 @@ console.log(factorial(5));
3535

3636
// write the above function in a recursive way.
3737

38+
function rFactorial(n) {
39+
if (n === 0) return 1;
40+
return n * rFactorial(n - 1);
41+
}
42+
3843
// when your code is ready, un-comment the next line and run the file
39-
// console.log(recursiveFactorial());
44+
console.log(rFactorial(5));

0 commit comments

Comments
 (0)