sumAll
We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.
Examples
sumAll([1, 4]) → 10
sumAll([4, 1]) → 10
Starter code
function sumAll(arr) {
}
Complexity of the optimal solution
Time O(n), space O(1). The function iterates from the smaller number to the larger number. If the difference between the numbers is n, the loop runs n times. The time complexity is linear relative to the range of numbers. Space is constant.