Recursive function as block value

Sure! The simplest way to do this one is:

function fib(n)  {
  if (n == 0) return 0;
  if (n == 1) return 1;
  return fib(n - 1) + fib(n - 2);
}

Observable pulls out the name from function declarations (function ___) and class declarations (class ___), so they work without needing an additional = - other cells can reference fib by name.

6 Likes