Last active
April 26, 2024 05:09
-
-
Save fitsum/d60e6ebb3676347b5eb7ee9195c9a0d2 to your computer and use it in GitHub Desktop.
Add, subtract, multiply, divide - practical JS closure/currying
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
maths = function(opp, a) { | |
checkNum = function(num) { | |
if (typeof num !== 'number') { | |
throw "Error: Quiting because '" + num + "' isn't a number"; | |
} | |
} | |
checkNum(a); | |
return function(b) { | |
[a, b].forEach(function(n) { | |
checkNum(n); | |
}); | |
return eval([b, opp, a].join("")); | |
} | |
} | |
//TODO: ES? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment