Skip to content

Instantly share code, notes, and snippets.

@TGOlson
Last active March 22, 2016 19:30
Show Gist options
  • Save TGOlson/ba89c89aa6625f90d719 to your computer and use it in GitHub Desktop.
Save TGOlson/ba89c89aa6625f90d719 to your computer and use it in GitHub Desktop.
Point free factorial kata
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