arr = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
.[ 1, 3, 6, 10, 15, 21, 28, 36 ]
. const newArr = arr.reduce((acc, n, i) => (acc.push(n + (acc[i - 1] ?? 0)), acc), []);
// или
const newArr = arr.reduce((acc, n) => (acc[0].push(acc[1] += n), acc), [ [], 0 ])[0];
// или
const newArr = arr.map((n, i, a) => eval(a.slice(0, i + 1).join('+')));
// или
const newArr = arr.map((n, i, a) => a.reduce((acc, m, j) => acc + m * (j <= i), 0));
arr.forEach((n, i, a) => a[i] += a[i - 1] ?? 0);
const createSequence = numbers => {
const store = numbers.reduce((accumulator, number) => {
accumulator.intermediateValue += number;
accumulator.sequence.push(accumulator.intermediateValue);
return accumulator;
}, {
sequence: [],
intermediateValue: 0
});
return store.sequence;
};