Javascript-Will recursion be used in actual projects?

Source: Internet
Author: User
In actual projects, what scenarios will recursion be used? How to Design recursion? In actual projects, what scenarios will recursion be used?
How to Design recursion?

Reply content:

In actual projects, what scenarios will recursion be used?
How to Design recursion?

The most common and easy-to-understand examples of recursive thinking are tree trees. Recursive thinking is also one of the most important basic ideas in software development, as @ _ yeshuai said. At the same time, there is no necessary relationship with the code, as you have commented on.

If a solution uses too deep recursive depth, does it mean this solution is not suitable for Recursive solutions?

In my opinion, the most important thing is to have this way of thinking, rather than writing recursive code. After all, recursion does affect efficiency.

Recursion is used in common tree structures, such as infinitus classification and folder traversal.

Recursion is certainly used.
With this questiontagFor example, you can try to usejsImplement the directory tree structure. There is no limit on the hierarchy. There may be only two layers, and there may be five layers, depending on the data.

Many algorithms must be implemented through recursion ~

For example, query all levels of subordinates under a supervisor, for example, query all level 2 and level 3 categories under a level 1 product category.
Remember to set the recursion termination conditions during recursion.

Trace is commonly used for hierarchical operations. For example, if this node is not configured, the data of the previous node is read.

Occasionally, such as infinitus classification and classification systems, such as the mall background and blog list

For example, to deeply copy a menu with an infinite number of js objects
How to design it depends on your specific application scenarios

You can view my notes for deep copying of js objects.
Https://segmentfault.com/n/1330000004855030

Occasionally used, not frequently used

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.