I asked a question before about using lazy evaluation in Scala. I was trying to write the following Haskell function in Scala:
fib a b = c : (fib b c)
where c = a+b
The answer to that question was that I couldn't use Lists, but should rather use Streams. Now I'm trying to do the same thing in Javascript. I translated the function, and tried it on this site:
function fib(a,b) {
c = a+b;
return [c] + fib(b,c);
}
var res = fib(0,1).slice(0,10);
console.log(res);
But I get the following error:
RangeError: Maximum call stack size exceeded
Does Javascript have a way to do this?