v likeblog.iread.fun·Jan 22, 2024Js 不导致栈溢出的递归函数堆栈溢出 递归函数(Recursive Function)如果调用自身次数过多,超过栈大小限制,就会导致栈溢出。 一个典型的例子是,用递归函数简陋实现斐波那契数列,如果调用参数过大,将导致栈溢出: function fibonacci(n) { if (n < 2) return n; return fibonacci(n - 1) + fibonacci(n - 2); } for (let n = 0; n < 100; n++) { console.log(`fibo ${n...31 readsJavaScript
v likeblog.iread.fun·Jan 22, 2024Recursive functions don't casue stack overflow in JSStack Overflow Recursive functions can cause a stack overflow if they call themselves too many times and exceed the stack size limit. A classic example of a recursive function that can exceed the stack size limit if called with a large input is the n...JavaScript
Erman İmerermanimer.hashnode.dev·Jul 27, 2023Tail Call Optimization In ElixirA tail-recursive function executes itself as the last thing. def fun(...) do ... fun(...) end Elixir optimizes tail calls by reusing the last stack frame of the function, thus avoiding the typical stack push and reducing the overhead of crea...103 readsElixir