+ 1

Please explain better on using the recursion function

Recursion function

23rd Jul 2019, 12:14 AM
chisom chineme
5 Respostas
+ 5
A recursive function is simply a function that calls itself, and typically performs some other task before calling itself again. A very simple example might be: function subtractToOne(num){ console.log(num); num--; if(num >= 1){subtractToOne(num));} } subtractToOne(3); The output will be: 3 2 1 The idea is that if the function is called with an argument greater than or equal to 1, it will call itself again with the previous argument reduced by 1 and keep calling itself until its argument is less than 1. I hope this helps!
23rd Jul 2019, 1:08 AM
Mike Perkowski
Mike Perkowski - avatar
+ 4
Sometines it could be an alternative to using a loop.
23rd Jul 2019, 3:36 AM
Sonic
Sonic - avatar
+ 1
So what does it do please
23rd Jul 2019, 12:40 AM
chisom chineme
0
Thanks to you all, they helped me alot
28th Jul 2019, 9:49 PM
chisom chineme