Created
April 18, 2013 05:38
-
-
Save web20opensource/5410388 to your computer and use it in GitHub Desktop.
Is this a validated response about the last minutes from the video of Doug Crawford at mjg.in?
http://frontendmasters.com/courses/javascript-the-good-parts/douglas-crockfords-function-challenges/
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
var add = function (add){ return add}; | |
var mul = function (mul){ return mul}; | |
var op = add || mul; | |
var applyf = function(op){ | |
if ( op === add) | |
return function(x){ | |
return function(y){ | |
return x+y; | |
} | |
}; | |
else if ( op === mul) | |
return function(x){ | |
return function(y){ | |
return x*y; | |
} | |
}; | |
} | |
addf = applyf(add); | |
alert ( addf(3)(4) ); | |
alert ( applyf(mul)(5)(6) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just some basic js stuff!
Write a function that takes a binary function and makes it callable with two invocations
//
addf = applyf(add);
alert ( addf(3)(4) ); // 7
alert ( applyf(mul)(5)(6) ); // 30