I am working on a running sum problem and I keep getting an array of undefined for my output. Here is the example of what the output should be like
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3,6,10]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
here is the work I have so far:
var runningSum = function(arr) {
const sum = arr.map(n => {
for (let i = 0; i < arr.length; i++) {
if (i === 0) {
n + 0
} else {
n + arr[i - 1]
}
}
})
return sum
};
const arr = [1, 2, 5, 4]
runningSum(arr)