Write a JS function that calculates the total accumulated value for a monetary deposit by given principal sum, interest rate, compounding frequency and overall length. At the beginning of the task you are given the compounding period, which is inversely related to the frequency. You need to express the frequency as how many times in a year the interest is compounded. For instance, a 3-month period means the interest will be updated 4 times in a year. Any percentages need to be expressed as a fraction.
The input comes as an array of numbers:
-
The first value is the principal sum
-
The second is the interest rate in percent
-
The third is the compounding period in months
-
The final value is the total time span, given in years.
Examples:
Input:
[1500, 4.3, 3, 6]
Output:
1938.84
Input:
[100000, 5, 12, 25]
Output:
338635.49
The output should be printed to the console, with two decimal places.