We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a91251 commit 26c0a84Copy full SHA for 26c0a84
part5 (Functions)/Recursion/recursion.js
@@ -0,0 +1,24 @@
1
+/*
2
+INFO: What is Recursion ?
3
+Recursion is when a function calls itself to solve a smaller version of a problem until it reaches a base case (a condition to stop calling itself)
4
+*/
5
+
6
+function recursiveFunction() {
7
+ if (baseCondition) {
8
+ return result; // stop calling itself
9
+ } else {
10
+ return recursiveFunction(); // calls itself again
11
+ }
12
+}
13
14
+// Example
15
+function countdown(n) {
16
+ if (n <= 0) {
17
+ console.log("Done!");
18
+ return;
19
20
21
+ console.log(n);
22
+ countdown(n - 1); // recursive call
23
24
+countdown(3);
0 commit comments