repl.it
@shamdasani/

Y-Combinator

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const y = (x => f => (...a) => f(x(x)(f))(...a))(x => f => (...a) =>
  f(x(x)(f))(...a)
);

function fibonacciFactory(f) {
  return function thunk(n) {
    if (n === 0 || n === 1) {
      return 1;
    }
    return f(n - 2) + f(n - 1);
  };
}

const fibonacci = y(fibonacciFactory);
fibonacci(10);
Native Browser JavaScript