From 31b2dd45ac7bcd4e3a88a193ce9043f161e5a826 Mon Sep 17 00:00:00 2001 From: nourmhassan Date: Fri, 23 Feb 2018 11:44:40 -0800 Subject: [PATCH 1/2] nour hassan --- recursion.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/recursion.js b/recursion.js index b4b66d1..deb89ac 100644 --- a/recursion.js +++ b/recursion.js @@ -10,9 +10,15 @@ while (n <= 10) { // write a recursive - function called countToTen that mimics the while loop above. // code here +const countToTen = num => { + if (num > 10) return; + console.log(`while loop ${num}`); + countToTen(++num) +}; +countToTen(1); // when you code is ready, un-comment the next line and run the file -// console.log(countToTen()); + console.log(countToTen(1)); /* ================ Next Problem ================= */ // Problem 2: @@ -28,6 +34,11 @@ const factorial = n => { console.log(factorial(5)); // write the above function in a recursive way. +const recursiveFactorial = n => { +if (n === 0) return 1; +return n * recursiveFactorial(n - 1); +}; + // when your code is ready, un-comment the next line and run the file -// console.log(recursiveFactorial()); + console.log(recursiveFactorial(5)); From 9f9943bc87861121dba54c0d8d473242df2342da Mon Sep 17 00:00:00 2001 From: nourmhassan Date: Sun, 25 Feb 2018 11:18:46 -0800 Subject: [PATCH 2/2] nour hassan js-mini fixed --- recursion.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/recursion.js b/recursion.js index deb89ac..04dbf0e 100644 --- a/recursion.js +++ b/recursion.js @@ -15,10 +15,9 @@ const countToTen = num => { console.log(`while loop ${num}`); countToTen(++num) }; -countToTen(1); // when you code is ready, un-comment the next line and run the file - console.log(countToTen(1)); +console.log(countToTen(1)); /* ================ Next Problem ================= */ // Problem 2: @@ -35,10 +34,10 @@ console.log(factorial(5)); // write the above function in a recursive way. const recursiveFactorial = n => { -if (n === 0) return 1; -return n * recursiveFactorial(n - 1); + if (n === 0) return 1; + return n * recursiveFactorial(n - 1); }; // when your code is ready, un-comment the next line and run the file - console.log(recursiveFactorial(5)); +console.log(recursiveFactorial(5));