1function recurse(arr=[])
2{
3 // base case, to break the recursion when the array is empty
4 if (arr.length === 0) {
5 return;
6 }
7
8 // destructure the array
9 const [x, ...y] = arr;
10
11 // Do something to x
12
13 return recurse(y);
14}
1// program to count down numbers to 1
2function countDown(number) {
3
4 // display the number
5 console.log(number);
6
7 // decrease the number value
8 const newNumber = number - 1;
9
10 // base case
11 if (newNumber > 0) {
12 countDown(newNumber);
13 }
14}
15
16countDown(4);
1var countdown = function(value) {
2 if (value > 0) {
3 console.log(value);
4 return countdown(value - 1);
5 } else {
6 return value;
7 }
8};
9countdown(10);