I have items in my list and the items have a field, which shows the creation date of the item.
and I need to group them based on a "compression", which the user gives. The options are Day
, Week
, Month
and Year
.
If the user selects day
compression, I need to group my items as such that the items, which are created in the same day, will be groupped. In my example above, only item 1 and item 2 are created in the same day. The others are also groups but they will have only one item because at their day, only one item is created.
{{item1, item2}, {item3}, {item4}, {item5}, {item6}, {item7}}
If the user selects week
:
{{item1, item2, item3, item4}, {item5}, {item6}, {item7}}
If the user selects month
:
{{item1, item2, item3, item4, item5}, {item6}, {item7}}
If the user selects year
:
{{item1, item2, item3, item4, item5, item6}, {item7}}
After groups are created, the date of the items are not important. I mean the key can be anything, as long as the groups are created.
In case of usage of Map
, I thought as the keys as follow:
day
= day of the year
week
= week of the year
month
= month of the year
year
= year
What would be the best solution to this problem? I could not even start it an I cannot think of a solution other than iteration.
See Question&Answers more detail:
os