the project requires the implementation of a date grouping function in Wechat"s moments:
as shown in the figure above, it includes grouping by year, grouping content on the same day, and supporting paging. Now the data returned by the background is sorted:
{
"2018":{
"10-1":[{"title":"1","content":"1"}],
"9-1"[{"title":"2","content":"2"},{"title":"3","content":"3"}]
},
"2017":{
"10-1":[]
}
}
then iterate through this object, and as a result, when writing the code, we find that we have to write the nesting of more than three for loops, and then add the data to the list, and the code becomes more complicated instantly. I would like to ask you, how does this function organize the structure of data, or is there any elegant way, such as recursion?