@@ -41,11 +41,11 @@ Functions that operate on other functions, either by taking them as arguments or
41
41
42
42
``` javascript
43
43
let sum = (x , y ) => {
44
- return x + y;
44
+ return x + y;
45
45
}
46
46
47
47
let calculate = (fn , x , y ) => {
48
- return fn (x, y);
48
+ return fn (x, y);
49
49
}
50
50
51
51
calculate (sum, 1 , 2 );
@@ -56,9 +56,9 @@ calculate(sum, 1, 2);
56
56
57
57
``` javascript
58
58
let students = [
59
- {name: ' Anna' , grade: 6 },
60
- {name: ' John' , grade: 4 },
61
- {name: ' Maria' , grade: 9 }
59
+ {name: ' Anna' , grade: 6 },
60
+ {name: ' John' , grade: 4 },
61
+ {name: ' Maria' , grade: 9 }
62
62
];
63
63
64
64
let isApproved = (student ) => {
@@ -84,9 +84,9 @@ students.map(byName);
84
84
85
85
``` javascript
86
86
let students = [
87
- {name: ' Anna' , grade: 6 },
88
- {name: ' John' , grade: 4 },
89
- {name: ' Maria' , grade: 9 }
87
+ {name: ' Anna' , grade: 6 },
88
+ {name: ' John' , grade: 4 },
89
+ {name: ' Maria' , grade: 9 }
90
90
];
91
91
92
92
let isApproved = (student ) => {
@@ -105,7 +105,7 @@ students.filter(isApproved).map(byName));
105
105
106
106
``` javascript
107
107
let totalGrades = students .reduce ((sum , student ) => {
108
- return sum + student .grade ;
108
+ return sum + student .grade ;
109
109
}, 0 );
110
110
111
111
totalGrades
@@ -119,10 +119,10 @@ Whenever a function calls itself, creating a loop.
119
119
120
120
``` javascript
121
121
let countdown = (num ) => {
122
- if (num > 0 ) {
123
- console .log (num);
124
- countdown (num - 1 );
125
- }
122
+ if (num > 0 ) {
123
+ console .log (num);
124
+ countdown (num - 1 );
125
+ }
126
126
}
127
127
128
128
countdown (5 );
@@ -139,11 +139,11 @@ countdown(5);
139
139
140
140
``` javascript
141
141
let factorial = (num ) => {
142
- if (num <= 0 ) {
143
- return 1 ;
144
- } else {
145
- return (num * factorial (num - 1 ));
146
- }
142
+ if (num <= 0 ) {
143
+ return 1 ;
144
+ } else {
145
+ return (num * factorial (num - 1 ));
146
+ }
147
147
}
148
148
149
149
factorial (5 );
@@ -172,7 +172,7 @@ Extract data from arrays or objects using a syntax that mirrors the construction
172
172
173
173
``` javascript
174
174
let foo = () => {
175
- return [1 , 2 , 3 ];
175
+ return [1 , 2 , 3 ];
176
176
};
177
177
178
178
let [a, b] = foo ();
@@ -192,7 +192,7 @@ console.log(a, b);
192
192
193
193
``` javascript
194
194
let ajax = function ({ url = " localhost" , port: p = 80 }, ... data ) {
195
- console .log (" Url:" , url, " Port:" , p, " Rest:" , data);
195
+ console .log (" Url:" , url, " Port:" , p, " Rest:" , data);
196
196
};
197
197
198
198
ajax ({ url: " someHost" }, " additional" , " data" , " hello" );
@@ -209,9 +209,9 @@ Taking a function that takes multiple arguments and turning it into a chain of f
209
209
210
210
``` javascript
211
211
let student =
212
- name =>
213
- grade =>
214
- ` Name: ${ name} | Grade: ${ grade} ` ;
212
+ name =>
213
+ grade =>
214
+ ` Name: ${ name} | Grade: ${ grade} ` ;
215
215
216
216
student (" Matt" )(8 );
217
217
// Name: Matt | Grade: 8
@@ -221,9 +221,9 @@ student("Matt")(8);
221
221
222
222
``` javascript
223
223
let currySum =
224
- x =>
225
- y =>
226
- x + y;
224
+ x =>
225
+ y =>
226
+ x + y;
227
227
228
228
let addFive = currySum (5 );
229
229
addFive (10 );
0 commit comments