Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 620b8b7

Browse files
authored
Update README.md
1 parent 0e1a35f commit 620b8b7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,27 @@ console.log(getSalutation(10)); // Good Morning
6969
```
7070

7171
<a href="https://codepen.io/Bunlong/pen/mjwWeY" target="_blank">Edit on Codepen</a>
72+
73+
## Higher Order Functions
74+
75+
A function that accepts another function as a parameter, or returns another function.
76+
77+
For example:
78+
79+
```javascript
80+
function mapConsecutive(values, fn) {
81+
let result = [];
82+
83+
for(let i=0; i < values.length -1; i++) {
84+
result.push(fn(values[i], values[i+1]));
85+
}
86+
87+
return result;
88+
}
89+
90+
const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
91+
let twoByTwo = mapConsecutive(letters, (x, y) => [x, y]);
92+
console.log(twoByTwo); // [[a, b], [b, c], [c, d], [d, e], [e, f], [f, g]]
93+
```
94+
95+
<a href="https://codepen.io/Bunlong/pen/JBJWRa" target="_blank">Edit on Codepen</a>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /