Functional-Light-JS ---- Recursion

本文探讨了JavaScript中的递归,包括定义、好处、互递归、弊端、尾调用和优化方法。递归可提高代码可读性,但也可能导致堆栈内存泄露。尾调用优化是解决这一问题的一种策略,而在ES6严格模式下,可以利用尾调用优化避免无限递归。此外,文章还提到了蹦床函数和连续传递函数作为递归优化的实用技巧。
摘要由CSDN通过智能技术生成

递归

  1. 递归的定义
  2. 递归的好处
  3. 互递归
  4. 递归的弊端
  5. 尾调用
  6. 递归的优化
递归的定义

递归就是一个函数在其内部调用它自己,同时有一个条件来终止这个递归的循环调用。

递归的好处

递归可以使我们的代码更加的接近声明式的代码,可读性会更加好一些。

	The most commonly cited reason that recursion fits the spirit of FP is because it trades (much of) 
	the explicit tracking of state with implicit state on the call stack. Typically, recursion is most useful
	when the problem requires conditional branching and back-tracking, and managing that kind
	of state in a purely iterative environment can be quite tricky; at a minimum, the code is highly 
	imperative and harder to read and verify. But  tracking each level of branching as its own scope 
	on the call stack often significantly cleans up the readability of the code.
互递归

互递归(Mutual Rescursion)就是当两个或多个函数在递归循环中相互调用时,这称为互递归。
exa

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值