Last active
December 13, 2015 23:09
-
-
Save cpsubrian/4989424 to your computer and use it in GitHub Desktop.
Function generators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addX (x) { | |
| return function (a) { | |
| return a + x; | |
| } | |
| } | |
| var add5 = addX(5); | |
| var add10 = addX(10); | |
| // What is result? | |
| var result = add10(add5(addX(4)(6))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PART TWO | |
| function addX (x) { | |
| return function (a) { | |
| return a + x; | |
| } | |
| } | |
| var makeAdd5 = addX.bind(null, 5); | |
| var add5 = makeAdd5(); | |
| // What is result? | |
| var result = add5.apply(null, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmmm I'm guessing 15, but less confident in my answer...