Last active
September 18, 2020 03:13
-
-
Save NobukazuHanada/11658189c496a97a4004 to your computer and use it in GitHub Desktop.
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 (global) | |
{ | |
var expr = function (n) | |
{ | |
var utilities = { | |
"+": function (a) { return function(b){ return a + b; } }, | |
"-": function (a) { return function(b){ return a - b; } }, | |
"*": function (a) { return function(b){ return a * b; } }, | |
"/": function (a) { return function(b){ return a / b; } } | |
}; | |
return function outer(op) | |
{ | |
if (op === "=") return n; | |
return function (m) | |
{ | |
n = utilities[op](n)(m); | |
return outer; | |
} | |
}; | |
}; | |
global.expr = expr; | |
})(window); | |
console.log( expr(4)("+")(3)("*")(2)("-")(1)("=") ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment