I have an object:
const transaction = [{
created: 1200,
amount: 200
},{
created: 1200,
amount: 400
},{
created: 1400,
amount: 400
},{
created: 1400,
amount: 300
},{
created: 1500,
amount: 100
}]
Everytime created has the same value I want to sum the amount's of the objects. So for example created: 1200 would have an amount of: 600 in total, because multiple created's where at 1200 so the amount got summed up.
Array.prototype.reduceto sum up the values. But I can't figure out the logic to only use it on the appriopriate object.reducesounds like the right idea - can you share your attempt?reduce, so you check for the value ofcreatedbefore summing.