Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9706a75

Browse files
authored
Update LESSONPLAN.md
1 parent d1d987c commit 9706a75

File tree

1 file changed

+85
-8
lines changed

1 file changed

+85
-8
lines changed

Week2/LESSONPLAN.md

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,101 @@ you can’t just call one function after another and hope they execute in the ri
7272
SECOND HALF (14.00 - 16.00)
7373

7474
## 4. Event loops
75-
7675
### Explanation
76+
https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/event_loop.md
7777
### Example
78+
79+
``` Javascript
80+
const bar = () => console.log('bar')
81+
82+
const baz = () => console.log('baz')
83+
84+
const foo = () => {
85+
console.log('foo')
86+
bar()
87+
baz()
88+
}
89+
90+
91+
foo()
92+
```
93+
Output:
94+
``` Javascript
95+
foo
96+
bar
97+
baz
98+
```
99+
100+
Call stack
101+
![Call Stack](assets/call_stack_example.png)
102+
78103
### Exercise
104+
79105
### Essence
80-
Notes:
81106

82-
- The event loop is part of the browser
83-
- It determines when any given function is executed
84107

85108

86109
## 5. 3 commonly used array functions (filter, reduce, map)
110+
87111
### Explanation
112+
**map**, **filter** and **reduce** are three array methods that iterate (loop!) over the whole array and preform a computation or a transformation.
113+
They have in common that they return a new array based on the transformations/calculations.
114+
115+
> [MDN definition](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map): The **map()** method creates a new array with the results of calling a provided function on every element in the calling array.
116+
117+
> [MDN definition](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter): The **filter()** method creates a new array with all elements that pass the test implemented by the provided function
118+
119+
> [MDN definition](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce): The **reduce()** method executes a **reducer** function (that you provide) on each member of the array resulting in a single output value†.
120+
121+
Writing the functions yourself: https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/map_filter.md
122+
88123
### Example
124+
```Javascript
125+
const numbers = [1, 2, 3, 4];
126+
const square = x => x * x;
127+
const squaredNumbers = numbers.map(square);
128+
129+
console.log(squaredNumbers); // -> [ 1, 4, 9, 16 ]
130+
```
131+
132+
```Javascript
133+
const numbers = [1, 2, 3, 2];
134+
const isTwo = x => x === 2;
135+
const Twos = numbers.filter(isTwo);
136+
137+
console.log(Twos); // -> [ 2, 4 ]
138+
```
139+
```Javascript
140+
const numbers = [1, 2, 3, 4];
141+
142+
const sum = (a, b) => a + b;
143+
const total = numbers.xxx(sum, 0);
144+
145+
console.log(total); // -> 10
146+
```
147+
148+
89149
### Exercise
90-
### Essence
91-
Notes:
150+
Fill in the xxx with map, filter or reduce:
151+
152+
``` Javascript
153+
const numbers = [1, 2, 3, 4];
154+
const doubled = numbers.xxx(item => item * 2);
155+
console.log(doubled); // [2, 4, 6, 8]
156+
```
157+
```Javascript
158+
const numbers = [1, 2, 3, 4];
159+
160+
const times = (a, b) => a * b;
161+
const total = numbers.xxx(times, 0);
92162

93-
- Array functions are predefined functions that come from the Array object
94-
- Each function serves to manipulate arrays in a specific way
163+
console.log(total); // -> 10
164+
```
165+
``` Javascript
166+
const numbers = [1, 2, 3, 4];
167+
const evens = numbers.xxx(item => item % 2 === 0);
168+
console.log(evens); // [2, 4]
169+
```
170+
171+
### Essence
95172

0 commit comments

Comments
 (0)