@shamdasani/

Y-Combinator

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5864813758132579","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"Y29uc3QgeSA9ICh4ID0+IGYgPT4gKC4uLmEpID0+IGYoeCh4KShmKSkoLi4uYSkpKHggPT4gZiA9PiAoLi4uYSkgPT4KICBmKHgoeCkoZikpKC4uLmEpCik7CgpmdW5jdGlvbiBmaWJvbmFjY2lGYWN0b3J5KGYpIHsKICByZXR1cm4gZnVuY3Rpb24gdGh1bmsobikgewogICAgaWYgKG4gPT09IDAgfHwgbiA9PT0gMSkgewogICAgICByZXR1cm4gMTsKICAgIH0KICAgIHJldHVybiBmKG4gLSAyKSArIGYobiAtIDEpOwogIH07Cn0KCmNvbnN0IGZpYm9uYWNjaSA9IHkoZmlib25hY2NpRmFjdG9yeSk7CmZpYm9uYWNjaSgxMCk7Cg=="},"asBuffer":null},"loaded":true}}
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