Skip to content

Commit 7d26a3c

Browse files
committed
Merge pull request #3 from raphaelpor/patch-1
Remove 'return' keywords
2 parents 4a93379 + 0132f56 commit 7d26a3c

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

README.md

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ Returns the same result given same parameters. It's execution doesn't depend on
1818

1919
```javascript
2020
let number = 1;
21-
let increment = () => {
22-
return number += 1;
23-
}
21+
22+
let increment = () => number += 1;
23+
2424
increment();
2525
// 2
2626
```
2727

2828
2) Pure
2929

3030
```javascript
31-
let increment = (n) => {
32-
return n + 1;
33-
}
31+
let increment = n => n + 1;
32+
3433
increment(1);
3534
// 2
3635
```
@@ -41,13 +40,9 @@ Functions that operate on other functions, either by taking them as arguments or
4140
1) Sum
4241

4342
```javascript
44-
let sum = (x, y) => {
45-
return x + y;
46-
}
43+
let sum = (x, y) => x + y;
4744

48-
let calculate = (fn, x, y) => {
49-
return fn(x, y);
50-
}
45+
let calculate = (fn, x, y) => fn(x, y);
5146

5247
calculate(sum, 1, 2);
5348
// 3
@@ -62,9 +57,7 @@ let students = [
6257
{name: 'Maria', grade: 9}
6358
];
6459

65-
let isApproved = (student) => {
66-
return student.grade >= 6;
67-
}
60+
let isApproved = student => student.grade >= 6;
6861

6962
students.filter(isApproved);
7063
// [ { name: 'Anna', grade: 6 }, { name: 'Maria', grade: 9 } ]
@@ -73,9 +66,7 @@ students.filter(isApproved);
7366
3) Map
7467

7568
```javascript
76-
let byName = (obj) => {
77-
return obj.name;
78-
}
69+
let byName = obj => obj.name;
7970

8071
students.map(byName);
8172
// [ 'Anna', 'John', 'Maria' ]
@@ -90,13 +81,9 @@ let students = [
9081
{name: 'Maria', grade: 9}
9182
];
9283

93-
let isApproved = (student) => {
94-
return student.grade >= 6;
95-
}
84+
let isApproved = student => student.grade >= 6;
9685

97-
let byName = (obj) => {
98-
return obj.name;
99-
}
86+
let byName = obj => obj.name;
10087

10188
students.filter(isApproved).map(byName);
10289
// ['Anna', 'Maria']
@@ -105,9 +92,7 @@ students.filter(isApproved).map(byName);
10592
5) Reduce
10693

10794
```javascript
108-
let totalGrades = students.reduce((sum, student) => {
109-
return sum + student.grade;
110-
}, 0);
95+
let totalGrades = students.reduce((sum, student) => sum + student.grade, 0);
11196

11297
totalGrades
11398
// 19
@@ -119,7 +104,7 @@ Whenever a function calls itself, creating a loop.
119104
1) Countdown
120105

121106
```javascript
122-
let countdown = (num) => {
107+
let countdown = num => {
123108
if (num > 0) {
124109
console.log(num);
125110
countdown(num - 1);
@@ -139,7 +124,7 @@ countdown(5);
139124
2) Factorial
140125

141126
```javascript
142-
let factorial = (num) => {
127+
let factorial = num => {
143128
if (num <= 0) {
144129
return 1;
145130
} else {
@@ -157,9 +142,7 @@ Given a value and a function, unwraps the values to get to its inner value(s), c
157142
1) Adding a value to all the elements in a array
158143

159144
```javascript
160-
let plus1 = (num) => {
161-
return num + 1;
162-
}
145+
let plus1 = num => num + 1;
163146

164147
let numbers = [1, 2, 3];
165148
numbers.map(plus1);
@@ -204,9 +187,7 @@ Extract data from arrays or objects using a syntax that mirrors the construction
204187
1) Select from pattern
205188

206189
```javascript
207-
let foo = () => {
208-
return [1, 2, 3];
209-
};
190+
let foo = () => [1, 2, 3];
210191

211192
let [a, b] = foo();
212193
console.log(a, b);

0 commit comments

Comments
 (0)