Last active
December 13, 2015 23:09
-
-
Save cpsubrian/4989424 to your computer and use it in GitHub Desktop.
Function generators.
This file contains 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 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); |
DING DING DING .... <hands merrick giant stuffed animal>
Hmmm I'm guessing 15, but less confident in my answer...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Um 25?