JS function recursion

Source: Internet
Author: User

Tag: equals the essential loop 10 s function recursive self function return


There are 200 of peaches in the park. Monkeys eat 10 a day, pick out two bad throw away, ask 6 days after the number of peaches remaining

/*var SL = 200;

for (Var i=0;i<6;i++)
{
SL = sl-12;
}

Alert (SL); */

The park has a bunch of peaches, the monkeys eat half a day, pick out a bad throw away, the 6th day when found to have 1 peaches, asked how many peaches

/*var SL = 1;

Number of the previous day = (number of current days + 1) * *;

for (Var i=0;i<6;i++)
{
SL = (sl+1) * *;
}

Alert (SL); */

Use the function to find
function function: Returns the number of peaches in the nth day

function self-Tune yourself

var sl;
function Shuliang (n)
{
When n equals 6 peach number is 1
if (n==6)
{
SL = 1;
}
Else
{
Find the number of the day
The number of the day = (number of next day + 1) * *;
SL = (Shuliang (n+1) +1) * *;
}

return SL; Returns the number of the day
}

Alert (Shuliang (0));

/*
Shuliang (0)
{
SL = (94+1) * *; Stuck
}


*/

The essence of recursion is to self-tune itself and can be seen as a nested loop of functions.

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.