Skip to content

Instantly share code, notes, and snippets.

@shellsong
Last active February 20, 2019 14:42
Show Gist options
  • Save shellsong/8c1caf18eb11052f82c4 to your computer and use it in GitHub Desktop.
Save shellsong/8c1caf18eb11052f82c4 to your computer and use it in GitHub Desktop.
YCombinator
const Y = require('./Y')
exports.fibonacci = Y((f) => (n) => n === 0 || n === 1 ? 1 : f(n - 1) + f(n - 2))
exports.factorial = Y((f) => (n) => n <= 0 ? 0 : (n === 1 ? 1 : n * f(n - 1)))
module.exports = (le) => ((f) => f(f))((f) => le((x) => (f(f))(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment