Skip to content

Instantly share code, notes, and snippets.

@web20opensource
Created April 18, 2013 05:38
Show Gist options
  • Save web20opensource/5410388 to your computer and use it in GitHub Desktop.
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/
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) );
@web20opensource
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment