Skip to content

Instantly share code, notes, and snippets.

@scarfunk
Forked from JamieDixon/gist:9661702
Last active September 11, 2015 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scarfunk/61fd300989f07324a89b to your computer and use it in GitHub Desktop.
Save scarfunk/61fd300989f07324a89b to your computer and use it in GitHub Desktop.
Calculating with functions
function zero(exp) { return numberExpression(0, exp); }
function one(exp) { return numberExpression(1, exp); }
function two(exp) { return numberExpression(2, exp); }
function three(exp) { return numberExpression(3, exp); }
function four(exp) { return numberExpression(4, exp); }
function five(exp) { return numberExpression(5, exp); }
function six(exp) { return numberExpression(6, exp); }
function seven(exp) { return numberExpression(7, exp); }
function eight(exp) { return numberExpression(8, exp); }
function nine(exp) { return numberExpression(9, exp); }
function numberExpression(num, exp)
{
return exp == undefined ? num : exp(num);
}
function plus(addend) { return function(augend) { return augend + addend; } }
function minus(addend) { return function(augend) { return augend - addend; } }
function times(addend) { return function(augend) { return augend * addend; } }
function dividedBy(addend) { return function(augend) { return augend / addend; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment