I would like help with a problem:
I have an array with several objects with two properties "Date" and "Amount"
The corresponding "Date" value is 1-12, they are months of the year.
The "Amount" value corresponds to the movement made. It will be positive if a value has been added, and it will be negative when a value is withdrawn.
"Ex:
var payments = [
{"amount": "123.00", "date": "01"},
{"amount": "123.00", "date": "01"},
{"amount": "-23.00", "date": "01"},
{"amount": "-23.00", "date": "01"},
{"amount": "23.00", "date": "01"},
{"amount": "123.00", "date": "02"},
{"amount": "123.00", "date": "02"},
{"amount": "-12.00", "date": "06"},
{"amount": "-10.00", "date": "06"},
{"amount": "-12.00", "date": "07"},
{"amount": "100.00", "date": "08"},
{"amount": "-100.00", "date": "08"},
];
I would like to take from this array the sum of all "amounts" that have the same "data" value, separating the negatives from the positives.
Ex:
In January[01], was added [123 + 123 + 23] = 269;
and has been withdrawn [- 23 - 23] = - 46;
In February[02] was added [123 + 123] = 246;
and no value was taken;
In August [08] was added [100];
and has been withdrawn [100];
I will use the data in an apex`s chart.
I believe that I could use several "IFs" for each month of the year, would that be it or could it be done in another way?
Thanks a lot for the help!