Feedback on Sum All Numbers in a Range solution

Tell us what’s happening:
So I managed to solve it and then took a look at the solution section and it mentions using math.min an max which I didn’t know about. I guess I’m wondering if I am fine without learning those. Originally I wanted to use recursion like in the fourth solution but I still struggle with understanding the proper way to use it I suppose. Anyway feedback is very much appreciated.

Your code so far

function sumAll(arr) {
  //establishes new Array;
  const newArr = [];
  //sorts the given array from lowest to highest
  const smallFirst = arr.sort((a,b) => a - b);
  //makes a new array with the two values and everything in between
  for (let i = smallFirst[0]; i <= smallFirst[1]; i++){
    newArr.push(i);
  }
 //returns the sum all  
 return newArr.reduce((acc,element) => acc + element);
}

sumAll([10, 5]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0

Challenge: Intermediate Algorithm Scripting - Sum All Numbers in a Range

Link to the challenge:

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