for example, I have a set of data
[
{
"time": "2018-03-01",
"data": 1,
},
{
"time": "2018-02-02",
"data": 2,
},
{
"time": "2018-01-01",
"data": 3,
},
{
"time": "2017-12-01",
"data": 4,
},
{
"time": "2017-11-02",
"data": 5,
},
{
"time": "2016-10-01",
"data": 6,
},
{
"time": "2016-9-01",
"data": 7,
}
]
the actual business scenario is to group this set of data into groups of 5 items, but these 5 items are also divided into groups according to their dates and years
for example, the result of the above seven items is:
[
{
section: 1,
sectionDatas: [
{
date: "2018",
datas: [
{
"time": "2018-03-01",
"data": 1,
},
{
"time": "2018-02-02",
"data": 2,
},
{
"time": "2018-01-01",
"data": 3,
}
]
},
{
date: "2017",
datas: [
{
"time": "2017-12-01",
"data": 4,
},
{
"time": "2017-11-02",
"data": 5,
}
]
}
]
},
{
section: 2,
sectionDatas: [
{
date: "2016",
datas: [
{
"time": "2016-10-01",
"data": 6,
},
{
"time": "2016-9-01",
"data": 7,
}
]
}
]
}
]
how to write this algorithm. Ask for advice