Hi, thought I’d use some old well known maths algorithm for the sum of an arithmetic series, after sorting the array, taking the difference plus 1 to get the number of terms etc…
function sumAll(arr) {
let sortArr = arr.sort( (a, b) => a > b);
let n = (sortArr[1] - sortArr[0] + 1);
return n/2 *[2 * sortArr[0] + (n - 1)*1 ];
}
sumAll([1, 4]);