I'm currently working on Node.js back-end application. In a nutshell, it should compute a deposit needed to return to previous average after several days of not making deposits.

Let's say, our average deposit during the first three days was 100. Then we were idle for 4 days, obviously our average would drop significantly. How do we figure out what a single deposit must to be to return to the previous average of 100?

Help will be greatly appreciated.

Keep track the latest day when any last deposit was made. Let's say the average deposit was

`X`

on day`a`

.After the idle period, on day

`b`

, the total money needed to submit to restore the previous average deposit -`(b - a) * X`

.In case average can be fraction number, you also need to consider whether you will do ceiling or flooring after the calculation based on your requirement.