-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
76 lines (63 loc) · 2.26 KB
/
classes.js
File metadata and controls
76 lines (63 loc) · 2.26 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Account {
constructor(accountName, transactionList, accountBalance) {
this.accountName = accountName;
this.transactionList = transactionList;
this.accountBalance = accountBalance;
}
filterTransactions(transactions) {
transactions.forEach(transaction => {
if (transaction.accountFrom === this.accountName
|| transaction.accountTo === this.accountName) {
this.transactionList.push(transaction)
}
})
}
logTransactions() {
console.log(` Total transactions found: ${this.transactionList.length}`);
this.transactionList.map(t => {
console.log(`
${t.date}: ${t.accountFrom} paid £${t.amount} to ${t.accountTo}
Ref: ${t.narrative}`);
})
}
calculateBalance() {
this.transactionList.forEach(t => {
if (this.accountName === t.accountTo) {
this.accountBalance += t.amount;
} else if (this.accountName === t.accountFrom) {
this.accountBalance -= t.amount;
}
})
}
logBalance() {
console.log(`Account balance: ${this.accountBalance.toFixed(2)}`)
}
}
class Transaction {
constructor(date, accountFrom, accountTo, narrative, amount) {
this.date = date;
this.accountFrom = accountFrom;
this.accountTo = accountTo;
this.narrative = narrative;
this.amount = amount;
}
}
class Bank {
constructor(transactionList, accountList) {
this.transactionList = transactionList;
this.accountList = accountList;
}
logAccounts() {
this.transactionList.forEach(transaction => {
for (let key in transaction) {
if (key === "accountFrom" || key == "accountTo") {
if (this.accountList.indexOf(transaction[key]) < 0) {
this.accountList.push(transaction[key])
}
}
}
});
this.accountList.map(account => console.log(account));
}
}
module.exports = { Account, Transaction, Bank }