Created
March 20, 2014 11:20
-
-
Save JamieDixon/9661702 to your computer and use it in GitHub Desktop.
Calculating with functions
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 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