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.

2 Answers

1
Kaidul On

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.

0
OlegArsyonov On

If someone is interested, I built the algorithm.

let x=(previousAveragePerDay*(datesConcluded+worthOfDiff))-r[0].sum;

where previousAveragePerDay is average during days of making a deposit datesConcluded is the number of days of making a deposit worthOfDiff is the number of days of not making a deposit r[0].sum is the sum of all deposits made