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

Skip to content

Commit 354ab43

Browse files
committed
Update week 6
1 parent 263ac0e commit 354ab43

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

JavaScript2/Week6/readme.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
Array functions
66
- [ ] ForEach
7-
- [ ] Map
8-
- [ ] Filter
7+
- [ ] [Map](#map)
8+
- [ ] [Filter](#filter)
9+
10+
[Arrow function](#Arrow-functions)
911

1012
Higher order functions
1113

@@ -67,7 +69,6 @@ console.log(carSpeeds); // [45, 87, 78]
6769
The filter function works on arrays and it filters out elements in our array.
6870
It takes a function as input. This function is called on every element in the array. Just like forEach. If this function we create returns true the element is saved in the, if we return false the element is filtered out.
6971

70-
7172
```js
7273

7374
// Lets get only cars with a speed larger than 60
@@ -86,9 +87,6 @@ console.log(fastCars); // logs the BMW and the Fiat
8687
```
8788

8889

89-
90-
91-
9290
### Sort
9391

9492
The sort function works on arrays. It sorts the elements of the array.
@@ -105,6 +103,35 @@ const sortedCars = cars.sort(function(a, b) {
105103
console.log(sortedCars); // it will return an array with the BMW object first, then the fiat and then the volvo
106104
```
107105

106+
### Arrow functions
107+
Functions can be written as arrow functions, it looks like this:
108+
109+
```js
110+
// This function
111+
function getTimesTen(a) {
112+
return a * 10;
113+
}
114+
115+
// Can be written like this:
116+
const getTimesTenArrowFunction = (a) => {
117+
return a * 10;
118+
}
119+
120+
// If there is only one parameter, we can remove the paranthesis:
121+
const getTimesTenArrowFunction = a => {
122+
return a * 10;
123+
}
124+
125+
// If the function is returning a single line of code, you can shorten it even further:
126+
const getTimesTenArrowFunction = a => a * 10;
127+
```
128+
129+
Here is how you **convert a function into an arrow function:**
130+
1. Remove the keyword function
131+
2. Add an arrow after the parameter
132+
3. If there is only one parameter, we can remove the paranthesis around the parameter
133+
4. If the function is returning a single line of code, we can remove the return keyword and the curly braces.
134+
108135

109136
### Chaining
110137
We can chain array methods after each other.

JavaScript2/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
55
| 4. | Browser environment<br>DOM manipulation <br> DOM event listeners | [Preparation](/JavaScript2/Week4/preparation.md) | [Homework](/JavaScript2/Week4/homework.md) |
66
| 5. | Functions advanced <br> Asynchronicity in js | [Preparation](/JavaScript2/Week5/preparation.md) | [Homework](/JavaScript2/Week5/homework.md) |
7-
| 6. | Array function <br> Higher order functions <br> Functional composition| [Preparation](/JavaScript2/Week6/preparation.md) | [Homework](/JavaScript2/Week6/homework.md) |
7+
| 6. | Array function <br> Arrow function <br> Higher order functions <br> Functional composition| [Preparation](/JavaScript2/Week6/preparation.md) | [Homework](/JavaScript2/Week6/homework.md) |

0 commit comments

Comments
 (0)