Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RangeError:我的第一个google脚本函数超过了最大调用堆栈大小_Javascript_Google Apps Script_Functional Programming_Google Apps - Fatal编程技术网

Javascript RangeError:我的第一个google脚本函数超过了最大调用堆栈大小

Javascript RangeError:我的第一个google脚本函数超过了最大调用堆栈大小,javascript,google-apps-script,functional-programming,google-apps,Javascript,Google Apps Script,Functional Programming,Google Apps,我开始研究Google Apps脚本,在我的第一个函数(一个简单的递归斐波那契函数)中,我收到了以下错误: RangeError:超过最大调用堆栈大小 好吧,好吧,使用递归方法的预期风险,有人能帮我解决我的错误吗 我的代码如下: 函数斐波那契(输入){ const number=parseInt(输入); if(number(console.log(`fib(${x})`),x); 函数斐波那契(输入){ const number=parseInt(输入); if(number(console.

我开始研究Google Apps脚本,在我的第一个函数(一个简单的递归斐波那契函数)中,我收到了以下错误:

RangeError:超过最大调用堆栈大小

好吧,好吧,使用递归方法的预期风险,有人能帮我解决我的错误吗

我的代码如下:

函数斐波那契(输入){
const number=parseInt(输入);
if(number<2){返回数;}
返回FIBONACCI(数字-1)+FIBONACCI(数字-2);
}

在fibuncai序列的算法中有两个递归步骤

return FIBONACCI(number - 1) + FIBONACCI(number - 2);
       ^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^^^^
因此,即使是相对较小的数量,也会将大量帧推送到调用堆栈上。以下是一个可视化:

const log=x=>(console.log(`fib(${x})`),x);
函数斐波那契(输入){
const number=parseInt(输入);
if(number<2){返回数;}
返回log(FIBONACCI(number-1))+log(FIBONACCI(number-2));
}

斐波那契(“10”)FIBUNCAI序列的算法中有两个递归步骤

return FIBONACCI(number - 1) + FIBONACCI(number - 2);
       ^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^^^^
因此,即使是相对较小的数量,也会将大量帧推送到调用堆栈上。以下是一个可视化:

const log=x=>(console.log(`fib(${x})`),x);
函数斐波那契(输入){
const number=parseInt(输入);
if(number<2){返回数;}
返回log(FIBONACCI(number-1))+log(FIBONACCI(number-2));
}

斐波那契(“10”)
Hey@bob,谢谢你的回复,作为一名开发人员,我知道递归斐波那契实现的风险。但作为一个简单的测试,我并不认为谷歌在这方面遇到了麻烦,但我已经改为交互式(使用循环
a)解决方案。obs.:我不太熟悉w/JS,我认为你编写三元运算符的方法与OCaml非常相似。嘿@bob,谢谢你的回答,作为一名开发人员,我知道使用递归斐波那契实现的风险。但作为一个简单的测试,我并不认为谷歌在这方面遇到了麻烦,但我已经改为交互式(使用循环
a)解决方案。obs.:我对w/JS不太熟悉,我认为您编写三元运算符的方法与OCaml非常相似。