function countup(n) {
if (n < 1) {
return [];
} else {
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5));
The value [1, 2, 3, 4, 5]
will be displayed in the console.
}
Here is recursion function with the result. The problem is I could not understand how it is working precisely step by step. Is there any one can explain it to me ?
Thanks in advance