-
-
Save qkdreyer/ecdaef8c198a120df3dfe9756c70e532 to your computer and use it in GitHub Desktop.
ES6 Y Combinator One Liner
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
// 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