I'm trying to build my own app, and I'm stuck at one issue that I cannot solve. My app deals with mortgages. I have several mortgages running in parallel, and I just need to sum-up total payments per period.
Let's say that we have the following arrays of objects (i.e. mortgages):
[ {uptomonth:84 , payment:150} ]
[ {uptomonth:120 , payment:200} ]
[ {uptomonth:120 , payment:100} , {uptomonth:180 , payment:250} , {uptomonth:300 , payment:500} ]
How to read this (example for 1st line): "up to month number 84, I pay $150 per month".
I want to combine arrays into one array (e.g. using array.concat...), then sort objects by "uptomonth" in order to obtain a result array like that:
[ {uptomonth:84,payment:1200} , {uptomonth:120,payment:1050} , {uptomonth:180,payment:750} , {uptomonth:300,payment:500} ]
The most difficult for me is to group by "uptomonth" (since there are duplicates of this value), and get the total payments per "uptomonth"...
Any idea of how to do that? Thanks a lot!