Skip to content

Commit db61f1b

Browse files
committed
Readme formatting tweaks
1 parent 4c32a7e commit db61f1b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# Recursion
2-
---
2+
33
##### **What is this?**
44
This is a repository of toy problems to be solved using recursion and JavaScript. While the concept of recursion may not be difficult to grasp, the only way to improve at thinking recursively is by practice. If you need practice, then maybe this repo is for you.
55

66
##### **A few guidelines:**
77
- Please refrain from sharing solutions. As crazy as it sounds, giving someone the answer doesn't help them. Instead, give them a question that encourages them to think differently.
8+
89
> **Q:** Why does my function keep exceeding the call stack?
910
> **A:** What's your base case?
11+
1012
- Don't be afraid to pseudocode your algorithm before writing actual code.
13+
1114
> Pseudocode helps you focus on the algorithm instead of getting distracted by syntax.
15+
1216
- This repo requires each function call itself recursively and pays no attention to whether inner recursive functions defined and called.
17+
1318
> While both are valid uses of recursion, there are important lessons to learn by following the method this repo enforces. Defining inner functions and calling them recursively relies on side effects, while following the more pure approach requires an understanding of how values are passed through the call stack.
19+
1420
- This repo restricts expanding the number of parameters a function accepts.
21+
1522
> Expanding the number of parameters is a valid approach, but has been restricted here to emphasize certain lessons while learning recursion.
23+
1624
- An attempt was made to order prompts by difficulty, but they don't have to be solved in any particular order.
1725
- Feel free to make pull requests or open issues regarding bugs or suggestions.
18-
- `Watch`, `Star`, and `Fork` this repo. You know you want to.
26+
- **`Watch`**, **`Star`**, and **`Fork`** this repo. You know you want to.
1927

2028
##### **How to use this repo:**
2129
1. Fork this repo and clone it to your local machine
@@ -29,8 +37,8 @@ This is a repository of toy problems to be solved using recursion and JavaScript
2937
> Recursion is when a function calls itself until it doesn't. --not helpful person
3038
3139
Is it a true definition? Mostly. Recursion is when a function calls itself. A recursive function can call itself forever, but that's generally not preferred. It's often a good idea to include a condition in the function definition that allows it to stop calling itself. This condition is referred to as a **_base_** case. As a general rule, recursion shouldn't be utilized without an accompanying base case unless an infinite operation is desired. This leaves us with two fundamental conditions every recursive function should include:
32-
- A `base` case
33-
- A `recursive` case
40+
- A **`base`** case
41+
- A **`recursive`** case
3442

3543
What does this all mean? Let's consider a silly example:
3644
```sh
@@ -45,6 +53,7 @@ function stepsToZero(n) {
4553
}
4654
```
4755
This function doesn't do anything meaningful, but hopefully it demonstrates the fundamental idea behind recursion. Simply put, recursion provides us a looping or repeating mechanism. It repeats an operation until a `base` condition is met. Let's step through an invocation of the above function to see how it evaluates.
56+
4857
1. Invoke `stepsToZero(n)` where `n` is the number `2`
4958
2. Is 2 zero?
5059
3. No, print message to console that 2 is not zero

0 commit comments

Comments
 (0)