JSFiddle - React, Tailwind, and code Playground
by Cody Lindley
HTML
<script src="https://dl.dropboxusercontent.com/u/2026291/firebug-lite-debug.js"></script>
JavaScript
//the mathOperation function returns a function
var mathOperation = function (operatorAsString) {
switch (operatorAsString) { //return a function
case '+': return function(x, y) { return x + y; };
case '+': return function(x, y) { return x + y; };
case '-': return function(x, y) { return x - y; };
case '*': return function(x, y) { return x * y; };
case '/': return function(x, y) { return x / y; };
};
};
console.log(mathOperation('+')(2, 2)); //logs 4
console.log(mathOperation('*')(2, 2)); //logs 4