Skip to content

Instantly share code, notes, and snippets.

@kasajian
Last active October 23, 2020 08:55
Show Gist options
  • Save kasajian/a4fc4d80c364f99ececce1fb8a08fabb to your computer and use it in GitHub Desktop.
Save kasajian/a4fc4d80c364f99ececce1fb8a08fabb to your computer and use it in GitHub Desktop.
recursive fatorial using y-combinator
var factorial = (f => {
return y => {
return f(y, f);
};
})((num, f) => {
return (num => {
if (num < 0) {
return -1;
} else if (num === 0) {
return 1;
} else {
return (num * f(num - 1, f));
}
})(num);
});
console.log(factorial(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment