showing results for - "countdown recursion javascript"
Jerónimo
11 Jun 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]
Louison
14 Sep 2017
1const recursiveRangeSum = (num, total = 0) => {  if (num <= 0) {    return total;  }  return recursiveRangeSum(num - 1, total + num);};