I have the data in the below format:
[
{
"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
}
]
And I want the result as below:
[
// 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
}
]
I found similar question, but I am not able to interrupt it, it is too complex for me...
I tried to use array.slice
method and get the first few terms. But it is not guarantee as the data is in different order every time. And I found some complex method on internet and it seems not work for me. So I would like to ask for help here.