I need help understanding how to utilize the index 0 within a for-loop while evaluating an empty array for cumulative sum. Additionally, I am looking to return zero when encountering a single negative value, and the summation process should halt upon encountering any negative number.
let sum = 0;
let lenArr = arr.length;
for (let i = 0; i <= lenArr - 1; i++) {
if (lenArr === 0) {
break;
}
if (arr[i] > 0) {
sum = sum + arr[i];
} else {
break;
}
}
return sum;
}
let input = [];
runningSum(input);