-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountStatement.js
More file actions
31 lines (25 loc) · 845 Bytes
/
AccountStatement.js
File metadata and controls
31 lines (25 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class AccountStatement {
constructor(transactions) {
this.transactions = transactions;
}
formatCredit(credit) {
return typeof credit === "number" ? credit.toFixed(2) : "";
}
formatDebit(debit) {
return typeof debit === "number" ? debit.toFixed(2) : "";
}
formatStatement() {
return this.transactions.reverse().map((transaction) => {
const credit = this.formatCredit(transaction.credit);
const debit = this.formatDebit(transaction.debit);
const balance = transaction.balance.toFixed(2);
const formattedValues = `${transaction.date} || ${credit} || ${debit} || ${balance}`;
return formattedValues;
});
}
displayStatement() {
console.log("date || credit || debit || balance");
console.log(this.formatStatement().join("\n"));
}
}
module.exports = AccountStatement;