I am assuming that this program should give the output [5,4,3,2,1] but it is giving [1,2,3,4,5]. Why this is happening? How the recursion is working here? Please explain me?
function countup(n) {
if (n < 1) {
// It is my base case
return [];
} else {
// This is my recursive function
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
console.log(countup(5));