I want to sum each price with pervious value as a new array this is my object and my final array I except with my reducer I write
data=[{price: 2, volume: 123}
{price: 3, volume: 123}
{price: 4, volume: 254}
{price: 1, volume: 444}
{price: 5, volume: 555}]
finaldata=[{price: 2, volume: 555}
1: {price: 5, volume: 777}
2: {price: 9, volume: 5000}
3: {price: 10, volume: 8000}
4: {price: 15, volume: 4000}]
const test = buy.map((items, index) =>
items.reduce((prev, curr, currIndex) => {
return index >= currIndex ? { volume: (prev?.volume || 0) + curr?.volume } : 0;
}, 0)
);
cons