Skip to content

Instantly share code, notes, and snippets.

@qkdreyer
Created Jun 9, 2018
Embed
What would you like to do?
ES6 Y Combinator One Liner
// http://kestas.kuliukas.com/YCombinatorExplained/
// https://rosettacode.org/wiki/Y_combinator#JavaScript
//
// const factorial = Y(next => (n) => {
// if (n < 2) return 1;
// return n * next(n - 1);
// });
// console.log(factorial(5)); // 120
const Y = f => (...args) => f(Y(f))(...args);
export default Y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment