JS function recursion

Source: Internet
Author: User

I. Description of KNOWLEDGE

function Fun () {    //  own call itself, called recursive call fun     ();    Console.log ("m2");} Fun ();

Second, function + variable

// to find the factorial of 5 with a recursive return // n! = n * (n-1)! // defines a function that is used to find the factorial of n function func (n) {    if (n = =1    )        {return 1;    }     // func (n-1) because the parameter passed is n-1, then it is the factorial    of (n-1) return N * func (n-1);} Console.log (     func (5)   );

Third, function + function

//  retracement question (Rabbit-born rabbit title )--From the 3rd month after birth of a pair of rabbits every month, the small rabbit to the third month after the birth of a pair of rabbits, if the rabbit is not dead, ask the number of rabbits each month is how many  // Span style= "COLOR: #008000" > yield analysis: 1, 1, 2, 3, 5, 8, 13, 21 ...  //  The number of rabbits in the nth month = total number of rabbits in n-1 month + total number of rabbits in n-2 months  //  question: Total number of rabbits for any month  function   func (n) { if  (n = = 0 | | n = = 1 return  1;  return  func (n-1) + func (n-2 var  a = func (22 

JS function recursion

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.