Skip to content

Instantly share code, notes, and snippets.

@NobukazuHanada
Created May 10, 2014 09:51
Show Gist options
  • Save NobukazuHanada/dd9ee9ae16080b80e959 to your computer and use it in GitHub Desktop.
Save NobukazuHanada/dd9ee9ae16080b80e959 to your computer and use it in GitHub Desktop.
(function (global)
{
var expr = function (n)
{
var utilities = {
"+": function (a, b) { return a + b; },
"-": function (a, b) { return a - b; },
"*": function (a, b) { return a * b; },
"/": function (a, 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