The challenge is to make a summing function that sums the two values in the array input, and every other integer in between.
The console says that there’s a potential infinite loop on line 4. But since I’ve put the if condition, shouldn’t that take care of the issue? Or is there something else wrong?
function sumAll(arr) {
let sum = arr[0] + arr[1];
if(arr[0] < arr[1]){
for(let i = arr[0] + 1; i++; i<= arr[1] -1){
sum = sum + i
}
} else {
for(let i = arr[1] + 1; i++; i<= arr[0] -1){
sum = sum + i
}
}
return sum
}
sumAll([1, 4])
Challenge: Sum All Numbers in a Range
Link to the challenge: