Cumulative Array Sum

Published by Николай in

Create a function that takes an array of numbers and returns an array where each number is the sum of itself + all previous numbers in the array.

Examples

CumulativeSum([1, 2, 3]) ➞ [1, 3, 6]

CumulativeSum([1, -2, 3]) ➞ [1, -1, 2]

CumulativeSum([3, 3, -2, 408, 3, 3]) ➞ [3, 6, 4, 412, 415, 418]

Notes

Return an empty array if the input is an empty array.

Watch a quick demo on how Edabit works.