JavaScript direct and reciprocal recursion

I know the basic concept of recursion, i.e. a function that calls itself recursion.

Now I went through the NodeJS documentation , I found something called Direct Recursion and Mutual Recursion . I found wikipedia documentation on mutual recursion. But you don’t know how this works with JavaScript. I have the following recursion questions.

  • How do function declarations and variable transfers work with mutual recursion?

  • Does direct recursion refer to the terminology of recursion?

Is this an example of direct recursion ?:

function abc(num,sum){
   if(num<=0) return sum;
   return abc(--num,sum);
}
+4
source share
1 answer
  • . , . , . , , , .

  • . . - , - , , , .

  • abs - .

, , .

:

function isOddDirect(n) {
  if (n < 1)
    return false;
  if (n === 1)
    return true;
  return isOddDirect(n-2);
}

:

function isOdd(num) {
  if (num === 1)
    return true;
  return !isEven(num-1);
}

function isEven(num) {
  if (num === 0)
    return true;
  return !isOdd(num-1);
} 

, , . , , , , . , , , .

() , , .

+1

Source: https://habr.com/ru/post/1690759/


All Articles