File tree Expand file tree Collapse file tree
09-An-Advanced-Look-at-Functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -270,9 +270,9 @@ console.log(thing);
270270console.log(thing.doSomething(50, 2)) // 100
271271*/
272272
273- // Higher Order Functions ******************************
273+ // Functions as Arguments ******************************
274274// Example 18
275-
275+ /*
276276console.log('\n')
277277function callThreeTimes(func) {
278278 func()
@@ -318,3 +318,7 @@ function pickOne(f1, f2) {
318318 }
319319}
320320pickOne(cry, rage)
321+ */
322+
323+ // Functions as Arguments ******************************
324+ // Example 18
Original file line number Diff line number Diff line change @@ -161,9 +161,7 @@ Functions that operate on/with other functions. They can:
161161- Accept other functions as arguments
162162- Return a function
163163
164- Functions that either accept functions as arguments and use them or do something with them or
165- a function that returns another function
166-
164+ Functions that either accept functions as arguments and use them or do something with them or a function that returns another function
167165```
168166function callTwice(func) {
169167 func();
@@ -178,3 +176,18 @@ callTwice(laugh); // pass function as an argument!
178176// "HAHAHAHAHAHAHAHAHAHA"
179177// "HAHAHAHAHAHAHAHAHAHA"
180178```
179+
180+ ## 7. Functions as Return Values
181+ Returning a function from within a function
182+ ```
183+ function makeBetweenFunc(min, max) {
184+ return function (val) {
185+ return val >= min && val <= max;
186+ }
187+ }
188+
189+ const inAgeRange = makeBetweenFunc(18, 100);
190+
191+ inAgeRange(17); // false
192+ inAgeRange(68); // true
193+ ```
You can’t perform that action at this time.
0 commit comments