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: Week5/REVIEW.md
+17-1Lines changed: 17 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,4 +7,20 @@ This review covers:
7
7
• JSON
8
8
• Map and filter
9
9
• Arrow functions
10
-
```
10
+
```
11
+
12
+
## Array Manipulations
13
+
14
+
As we know by now, arrays are collections of values.
15
+
16
+
As we will see, there are often many ways to achieve the same thing when working arrays. Over time, you will add different techniques to your mental toolbox to achieve the result you want quickly.
17
+
18
+
[Read more...](assets/array_manipulation)
19
+
20
+
## Map and filter
21
+
22
+
The array methods **map()** and **filter()** are best understood by looking at how they could be implemented if we were to write them ourselves. In the next few sections we will present simplified versions of the native implementations. We have prefixed the method names with `my` to distinguish them from the built-in versions.
Copy file name to clipboardExpand all lines: fundamentals/map_filter.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Map, filter
2
2
3
-
The array methods **map()**, **filter()**and **reduce()** are best understood by looking at how they could be implemented if we were to write them ourselves. In the next few sections we will present simplified versions of the native implementations. We have prefixed the method names with `my` to distinguish them from the built-in versions.
3
+
The array methods **map()**and **filter()** are best understood by looking at how they could be implemented if we were to write them ourselves. In the next few sections we will present simplified versions of the native implementations. We have prefixed the method names with `my` to distinguish them from the built-in versions.
4
4
5
-
Each of the three methods use a `for` loop internally. You will notice that once you start using these methods the need for `for` loops in your own code is greatly reduced (hurray!).
5
+
Each of the three methods use a `for` loop internally. You will notice that once you start using these methods the need for `for` loops in your own code is greatly reduced (hurray!).
6
6
7
7
## Array#map()\*
8
8
9
-
The **map** method returns a new array where each element of the subject array is transformed by a user-supplied transformation (= _mapping_) function.
9
+
The **map** method returns a new array where each element of the subject array is transformed by a user-supplied transformation (= _mapping_) function.
10
10
11
11
```js
12
12
Array.prototype.myMap=function (mapFn) {
@@ -20,7 +20,7 @@ Array.prototype.myMap = function (mapFn) {
20
20
21
21
<small>\* Array#map is a short-hand notation for Array.prototype.map.</small>
22
22
23
-
Because the **map()** method is called on an array (using dot-notation), the value of `this` refers to that array itself (in this review called the _subject_ array).
23
+
Because the **map()** method is called on an array (using dot-notation), the value of `this` refers to that array itself (in this review called the _subject_ array).
24
24
25
25
Internally, the **map()** method initializes a new, empty array to which it will push transformed elements, one by one, as it iterates through the subject array, calling the `mapFn` function for each individual element. When the loop has been completed, the new array is returned. Note that the subject array itself remains unmodified.
26
26
@@ -68,7 +68,7 @@ As is usual in JavaScript you do not necessarily have to use all the parameters
68
68
69
69
## Array#filter()
70
70
71
-
The **filter()** method returns a new array with all elements that pass the test implemented by a user-supplied (predicate\*) function.
71
+
The **filter()** method returns a new array with all elements that pass the test implemented by a user-supplied (predicate\*) function.
72
72
73
73
```js
74
74
Array.prototype.myFilter=function (predicateFn) {
@@ -132,7 +132,7 @@ The whole process is visualised in the figure below (the term _bucket_ was used
132
132
133
133

134
134
135
-
The **reduce()** method is the most flexible of the map/filter/reduce triplet. In fact, it is possible to rewrite **map()** and **filter** using **reduce()**.
135
+
The **reduce()** method is the most flexible of the map/filter/reduce triplet. In fact, it is possible to rewrite **map()** and **filter** using **reduce()**.
0 commit comments