recursion countdown javascript

Solutions on MaxInterview for recursion countdown javascript by the best coders in the world

showing results for - "recursion countdown javascript"
Salvatore
30 May 2016
1function countdown(n){
2  if (n < 1) {
3    return [];
4  } else {
5    const arr = countdown(n - 1);
6    arr.unshift(n);
7    return arr;
8  }
9}
10console.log(countdown(5)); // [5, 4, 3, 2, 1]
Camil
02 Apr 2017
1const recursiveRangeSum = (num, total = 0) => {  if (num <= 0) {    return total;  }  return recursiveRangeSum(num - 1, total + num);};