Last active
October 13, 2015 03:18
-
-
Save jaeschrich/4131436 to your computer and use it in GitHub Desktop.
A super-small javascript lambda function
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
/* | |
lamb.js | |
4 lines to lambda | |
*/ | |
function lamb(s){ | |
args = s.split("->") | |
return new Function(args[0], "return "+args[1]) | |
} | |
/* | |
Example | |
var five = lamb(”a -> a+1")(4) | |
Test code | |
if (!lamb("c -> c * 5)(6) === 30) throw new Error("Something's amiss...") | |
else console.log("Passed") | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment