Recursive function:

Recursion simply means calling a function from within!

This sentence is not hard to understand, as in a simple example of adding a value from 1 to 100:

function nums(n){     
    if(n === 1){
        return 1;
    }
    return nums(n - 1) + n; }
nums(100);
Copy the code

Three elements of recursion:

1. What does this function want to do

Column: The above example is to figure out the sum from 1 to 100Copy the code

2. Find the recursive end condition

Column: The column 100 above is the ending conditionCopy the code

3. Find out the equivalent relation of the function

Column: Nums (n-1) + n is the relationshipCopy the code