If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Recursion

Started by chinmay.sahoo, 01-11-2017, 07:31:40

Previous topic - Next topic

chinmay.sahooTopic starter

Recursion is an advanced topic, and you can certainly write JavaScript without using it. However in many situations, including some of the more
interesting examples later in this book, recursion is useful. A recursive function is usually one that calls itself. It is similar to a loop with or without a
terminating condition. Some programming functions lend themselves to recursive algorithms, such as the factorial one. The factorial is a classic
recursive algorithm because it is very obvious. A simple mathematical definition of the factorial operation is:

fact(0) = 1
fact(n) = n * fact(n–1)


Factorial is commonly represented by the exclamation mark (!).

With this algorithm, let's calculate 3!:

1. fact(3) = 3 * fact(2)
2. fact(2) = 2 * fact(1)
3. fact(1) = 1 * fact(0)
4. fact(0) = 1

As you can see, the algorithm works its way down from the given number to zero, so when it gets to fact(0) it must work its way back up to the
numbers.

We know that fact(0) = 1.
fact(1) = 1 * fact(0) = 1 * 1 = 1
fact(2) = 2 * fact(1) = 2 * 1 = 2
fact(3) = 3 * fact(2) = 3 * 2 = 6


raghuramastrologer

Recursion is the process which comes into existence when a function calls a copy of itself to work on a smaller problem. Any function which calls itself is called recursive function, and such function calls are called recursive calls.
  •  

Arunpolishetti

Can anyone help me to create a contact form for my wordpress site?
Arun
  •  



If you like SEOmastering Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...