Feedback on recursion please!

Tell us what’s happening:
Describe your issue in detail here.
i’m trying to solve this problem recursively. i have checked the answer but i’m still confused why is my solution wrong? as in what am i doing wrong? how do i think better for recursive problems?
thank you devs for your insights.

   **Your code so far**

function sumAll(arr) {
 //assigning variables to starting and ending range
 let [first,second]= [Math.min(arr[0],arr[1]),Math.max(arr[0],arr[1])]
 //if the first no reaches the second number
 if(first==second){
   return first
 }
   //add one to the upcoming number until second is reached
   return 1+sumAll([first+1,second]) 

}
// sumAll([5, 10])
console.log(sumAll([10, 5]))
/**
* 20,25
* 20+1
* (20+1)+1
* 
*/
   **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Sum All Numbers in a Range

Link to the challenge:

If you are summing all numbers in a range, you probably don’t want to add 1 here.

1 Like

any tips so i can become better at recursion? thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.