I have an array of objects:
struct Person {
let name: String
let dateOfBirth: Date
let money: Double
}
It contains people and how much money they have received or spent. The array contains 54 such objects. I need to find all objects with the same name and date fields and sum their money. That is, in the end, I have to get less than 54 records in my array.
Example: In the array, there are 3 records with the object John. For example, first, he received $15.0, then spent $7.0, and then received $4.0. For my task, I need to have 1 record in the array instead of 3 (with money filed as $12.0)
Does anyone have any idea?
Decimalnot with aDouble, otherwise you will start losing precision when summing values.