As a junior Web Developer seeking some guidance to solve a problem, I am reaching out here for the first time. Please bear with me if I miss any crucial details.
The data array I have looks like this:
[
{x: Date(1234), y: 0}
{x: Date(1235), y: 0}
{x: Date(1236), y: 300}
{x: Date(1237), y: 300}
{x: Date(1238), y: 300}
{x: Date(1239), y: 300}
{x: Date(1240), y: 300}
{x: Date(1241), y: 0}
{x: Date(1242), y: 0}
{x: Date(1243), y: 0}
]
I am looking to create a new array where consecutive 'y' values greater than 0 are summed up. The sum should be associated with the first 'x' value of the consecutive items, as shown below:
[
{x: Date(1234), y: 0}
{x: Date(1235), y: 0}
{x: Date(1236), y: 1500}
{x: Date(1241), y: 0}
{x: Date(1242), y: 0}
{x: Date(1243), y: 0}
]
I believe utilizing 'reduce' could help, but I am unsure about the exact steps to take. Any assistance on this matter would be highly appreciated.
Thank you in advance!