Tell us what’s happening:
This code works, is there a more elegant solution? Is created a new array and using reduce to sumAll in the array better?
Your code so far
function sumAll(arr) {
let total = 0;
for (let i = Math.min(...arr); i <= Math.max(...arr); i++){
total+= i;
}
return total;
}
sumAll([1, 4]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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