You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// to test these problems you can run 'node recursion.js' in your terminal
// Problem 1:
// let n = 1;
// while (n <= 10) {
// console.log("While Loop.. ", n);
// n++;
// }
// write a recursive - function called countToTen that mimics the while loop above.
// code here
// let count = 1;
// function countToTen() {
// if (count <= 10) {
// console.log("While loop", count);
// count++;
// countToTen();
// }
// }
// // when you code is ready, un-comment the next line and run the file
// console.log(countToTen());
/* ====================================================================== Next Problem ================================================================== */
// Problem 2:
// const factorial = n => {
// let result = 1;
// for (let i = 2; i <= n; i++) {
// result *= i;
// }
// return result;
// };
// console.log(factorial(5));
// write the above function in a recursive way.
constrecursiveFactorial=n=>{
if(n===0){
return1;
}
else{
returnn*recursiveFactorial(--n);
}
}
// when your code is ready, un-comment the next line and run the file