Skip to content

Instantly share code, notes, and snippets.

@jaeschrich
Last active October 13, 2015 03:18
Show Gist options
  • Save jaeschrich/4131436 to your computer and use it in GitHub Desktop.
Save jaeschrich/4131436 to your computer and use it in GitHub Desktop.
A super-small javascript lambda function
/*
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