Help! Sum All Numbers in a Range

Tell us what’s happening:

Your code so far
when i use min inside the recursive function it works if i pass min as an argument to the recursive function it says stack exceeded


function sumAll(arr) {
  let min=Math.min(...arr);
  let max=Math.max(...arr);
  let sum=function(mx,mi){
    if(mx<=mi)return mx;
    return mx+sum(mx-1);
  }
  return sum(max,min);
}

console.log(sumAll([10, 5]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-numbers-in-a-range/

The error “call stack exceeded” means “you have created infinite recursion”.

doesn’t this function take two arguments?

1 Like

Yeah Fixed it now works Thanks!!