I have the data structured as follows:
[
{
"Id": 1,
"Title": "Title_1",
"Positive": 5,
"CreateTs": 1674231433428
},
{
"Id": 2,
"Title": "Title_1",
"Positive": 8,
"CreateTs": 1674288139000
},
{
"Id": 3,
"Title": "Title_2",
"Positive": 5,
"CreateTs": 1674633970000
},
{
"Id": 4,
"Title": "Title_1",
"Positive": 12,
"CreateTs": 1674649613000
},
{
"Id": 5,
"Title": "Title_1",
"Positive": 10,
"CreateTs": 1674649741000
}
]
Desired result:
[
// group by Title, and CreateTs in current week
// Sum up the grouped number of Positive
{
"Title": "Title_1",
"Positive_sum": 22
},
{
"Title": "Title_2",
"Positive_sum": 5
}
]
Although I found a similar question, I couldn't fully comprehend it due to its complexity...
I attempted to use the array.slice
method to extract initial terms, but since the data order varies each time, this was not effective. After researching different methods online with no success, I'm seeking assistance here.