+ 1
Please explain better on using the recursion function
Recursion function
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!
+ 4
Sometines it could be an alternative to using a loop.
+ 1
So what does it do please
0
Thanks to you all, they helped me alot