Last active
March 22, 2016 19:30
-
-
Save TGOlson/ba89c89aa6625f90d719 to your computer and use it in GitHub Desktop.
Point free factorial kata
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
var R = require('ramda'); | |
// `proxy` is a function to allow for point-free recursion in JavaScrpipt | |
// it takes in a function name as a string, and returns a proxy function to the original function | |
var factorial = R.ifElse( | |
R.eq(0), R.always(1), | |
R.converge(R.multiply, R.I, R.compose(proxy('factorial'), R.dec)) | |
); | |
factorial(0); | |
// => 1 | |
factorial(5); | |
// => 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment