I have a struct that contains a date and quantity. I am trying to sum the quantity by either the month and year.
I thought of using Dictionary(grouping, by)
but the problem is I am able to only group by the date which is not what I want. Essentially, I need to group by the date and then do a reduce operation. Not sure how to accomplish this. I can always use the brut force method of looping through the array and aggregating the values, but I sure think there is a better way using map/reduce. Any ideas?
Appreciate your help!
struct Transaction {
var date = Date()
var quantity: Double
}
here is what I am looking for:
An array (that is sorted) or a dictionary with [month : sum of quantity]
for that month