Last active
February 3, 2023 09:00
-
-
Save jamigibbs/adafd95cf738fa872bda to your computer and use it in GitHub Desktop.
Calculating With Functions. eg. seven(times(five()));
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 makeNum(num, func) { | |
if (func === undefined) { | |
return num; | |
} else { | |
return func(num); | |
} | |
} | |
function zero(func) { | |
return makeNum(0,func); | |
} | |
function one(func) { | |
return makeNum(1,func); | |
} | |
function two(func) { | |
return makeNum(2,func); | |
} | |
function three(func) { | |
return makeNum(3,func); | |
} | |
function four(func) { | |
return makeNum(4,func); | |
} | |
function five(func) { | |
return makeNum(5,func); | |
} | |
function six(func) { | |
return makeNum(6,func); | |
} | |
function seven(func) { | |
return makeNum(7,func); | |
} | |
function eight(func) { | |
return makeNum(8,func); | |
} | |
function nine(func) { | |
return makeNum(9,func); | |
} | |
function plus(right) { | |
return function(left) { return left + right; }; | |
} | |
function minus(right) { | |
return function(left) { | |
return left - right; | |
}; | |
} | |
function times(right) { | |
return function(left) { return left * right; }; | |
} | |
function dividedBy(right) { | |
return function(left) { return left / right; }; | |
} | |
eight(minus(three())); // return 5 | |
six(dividedBy(two())); // return 3 | |
two(plus(five())); // return 7 | |
five(plus(two())); // return 7 | |
seven(times(five())); // return 35 | |
console.log(four(plus(nine()))); // must return 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jami, I need some clarity on this code can i get?