Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code javascript: Given a list of transactions within one year, calculate the final balance of an account. Add a fee for each month that did

code javascript: Given a list of transactions within one year, calculate the final balance of an account. Add a fee for each month that did not include at least three card payments for a total sum of at least 100.
Task description
You are given a list of all the transactions on a bank account during the year 2020. The account was empty at the beginning of the year (the balance was 0).
Each transaction specifies the amount and the date it was executed. If the amount is negative (less than 0) then it was a card payment, otherwise it was an incoming transfer (amount at least 0). The date of each transaction is in YYYYMMDD format: for example, 20200520 represents 20th May 2020.
Additionally, there is a fee for having a card (omitted in the given transaction list), which is 5 per month. This fee is deducted from the account balance at the end of each month unless there were at least three payments made by card for a total cost of at least 100 within that month.
Your task is to compute the final balance of the account at the end of the year 2020.
Write a function:
function solution(A, D);
that, given an array A of N integers representing transaction amounts and an array D of N strings representing transaction dates, returns the final balance of the account at the end of the year 2020. Transaction number K (for K within the range [0..N-1]) was executed on the date represented by D[K] for amount A[K].
Examples:
1. Given A =[100,100,100,10] and D =["20201231","20201222","20201203","20201229"], the function should return 230. Total income was equal to 100+100+10010=290 and the fee was paid every month, so 290-(5*12)=230.
2. Given A =[180,-50,-25,-25] and D =["20200101","20200101","20200101","20200131"], the function should return 25. The income was equal to 180, the expenditure was equal to 100 and the fee was applied in every month except January: 180-100-(5*11)=25.
3. Given A =[1,-1,0,-105,1] and D =["20201231","20200404","20200404","20200414","20200712"], the function should return -164. The fee is paid every month. 1-1+0-105+1-(5*12)=-164. Note that in April, even though the total cost of card payments was 106(more than 100), there were only two payments made by card, so the fee was still applied. A transaction of value 0 is considered a positive, incoming transfer.
4. Given A =[100,100,-10,-20,-30] and D =["20200101","20200201","20200211","20200205","20200208"], the function should return 80.
5. Given A =[-60,60,-40,-20] and D =["20201001","20200202","20201010","20201030"], the function should return 115.
Assume that:
N is an integer within the range [1..100];
each element of array A is an integer within the range [1,000..1,000];
D contains strings in YYYYMMDD format, representing dates in the range 20200101 to 20201231.
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

=+d) Perform the ANOVA and report your conclusions.

Answered: 1 week ago