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
Copy file name to clipboardExpand all lines: README.md
+67-1Lines changed: 67 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,16 +12,82 @@ No textbook is required for this workshop. All materials are included in this Gi
12
12
13
13
## Technical requirements
14
14
15
-
Laptop, Google Chrome browser and a text editor. If you do not have a text editor, we recommend Sublime Text, Atom or Visual Studio Code.
15
+
Laptop, Google Chrome browser and a text editor. If you do not have a text editor, we recommend Visual Studio Code, Sublime Text, or Atom.
16
16
17
17
# How to use this repository
18
18
19
19
### Let's get started...
20
20
21
+
Run the SpecRunner.html file in a browser. This document shows 4 failing tests.
22
+
23
+
The `spec` folder holds all the failing tests that are being displayed in SpecRunner.html. The `src` folder holds the functions that are being called to run the tests. Your task is to edit the filed in `src` to complete the functions and get the tests to pass. These files are just javascript files so you can use console.log to help debug and inspect these functions.
24
+
25
+
## Recursion Review
26
+
27
+
Recursion is a technique for solving problems wherein a function makes calls to itself. By doing so, it can complete a small amount of the processing, and delegate the rest of the problem to the recursive calls.
28
+
29
+
Consider the following function:
30
+
31
+
```
32
+
var eat = function(meal){
33
+
console.log('meal before bite:', meal);
34
+
console.log('now eating', meal.pop());
35
+
if(meal.length){
36
+
eat(meal);
37
+
} else {
38
+
console.log('done with the meal!');
39
+
}
40
+
}
41
+
```
42
+
43
+
Which produces this output:
44
+
45
+
```
46
+
eat(['soup', 'potatoes', 'fish']);
47
+
// => meal before bite: ["soup", "potatoes", "fish"]
48
+
// => now eating fish
49
+
// => meal before bite: ["soup", "potatoes"]
50
+
// => now eating potatoes
51
+
// => meal before bite: ["soup"]
52
+
// => now eating soup
53
+
// => done with the meal!
54
+
```
55
+
56
+
You can use recursion on problems where smaller parts of the problem look the same as the larger problem as a whole.
57
+
58
+
In this sprint, you'll be practicing writing recursive functions, building up to the reimplementation of a JavaScript browser method that involves recursion (getElementsByClassName). In so doing, don't use the things you're reimplementing, or any other built-in shortcuts that make these problems trivial. (You'll probably know if you're cheating, but feel free to ask us if you're not sure.)
59
+
60
+
(Curious fact: many browsers don't have any of these functions in them, and people do need to reimplement them. When we reimplement new browser functionality in older browsers, it's called a "polyfill".)
61
+
62
+
## Exercises
63
+
64
+
### 1: sumArray
65
+
66
+
-[ ] Implement `sumArray` with your own function in `src/sumArray.js`
67
+
68
+
### 2: power
69
+
70
+
-[ ] Implement `power` with your own function in `src/power.js`
71
+
72
+
### 3: nthFibonacci
73
+
74
+
-[ ] Implement `nthFibonacci` with your own function in `src/nthFibonacci.js`
75
+
76
+
### 4: getElementsByClassName
77
+
78
+
-[ ] Implement `getElementsByClassName` with your own function in `src/getElementsByClassName.js`
79
+
-[ ] You should use `document.body`, `element.childNodes`, and `element.classList`
80
+
- NOTE: You may also use methods from the [underscore](https://underscorejs.org) library for assitance, but are not required to do so.
81
+
- You can view the MDN documentation for getElementsByClassName [here](https://developer.mozilla.org/en/docs/Web/API/Document/getElementsByClassName)
82
+
21
83
#### Failing Test Example
22
84
85
+

86
+
23
87
#### Passing Test Example
24
88
89
+

90
+
25
91
### Don't forget..
26
92
27
93
You should throroughly read all of code in front of you and aim to understand line-by-line what is happening.
0 commit comments