Skip to content

Commit 02f04d7

Browse files
committed
Section 9:Functions as Return Values pt1
1 parent b853ff2 commit 02f04d7

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

09-An-Advanced-Look-at-Functions/01/01.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ console.log(thing);
270270
console.log(thing.doSomething(50, 2)) // 100
271271
*/
272272

273-
// Higher Order Functions ******************************
273+
// Functions as Arguments ******************************
274274
// Example 18
275-
275+
/*
276276
console.log('\n')
277277
function callThreeTimes(func) {
278278
func()
@@ -318,3 +318,7 @@ function pickOne(f1, f2) {
318318
}
319319
}
320320
pickOne(cry, rage)
321+
*/
322+
323+
// Functions as Arguments ******************************
324+
// Example 18

09-An-Advanced-Look-at-Functions/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff 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
```
168166
function 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+
```

0 commit comments

Comments
 (0)