Sum All Numbers in a Range Help

Sum All Numbers in a Range Help
0

#1

Tell us what’s happening:
My code is passing the first three tests but not the last two… which is weird because by the logic it should? Any help appreciated :slight_smile:

Your code so far

function sumAll(arr) {
  var big = Math.max(arr[0], arr[1]);
  return (big*(big+1)/2);
}

sumAll([1, 4]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

Looking back at this I am seeing that it returns 55 for [5, 10]. Obviously, my algorithm is because it is starting at 1 instead of arr[0].


#3

function sumAll(arr) {
var big = Math.max(arr[0], arr[1]);
var small = (Math.min(arr[0], arr[1]) -1);
return (big*(big+1)/2) - (small*(small+1)/2);
}

Fixed it