-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAccounts.js
More file actions
35 lines (31 loc) · 1.07 KB
/
createAccounts.js
File metadata and controls
35 lines (31 loc) · 1.07 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
const Account = require('./accountClass');
const accountExistsQ = require('./accountExistsQ');
function createAccounts()
{
for(let i in transactions)
{
if(!accountExistsQ(transactions[i].from))
{
//if the account does not exist,create the account
senderAccount = new Account(transactions[i].from,0);
accounts.push(senderAccount);
}
else
{
senderAccount = accounts.find(account => account.name === transactions[i].from);
}
if(!accountExistsQ(transactions[i].to))
{
//if the account does not exist,create the account
receiverAccount = new Account(transactions[i].to,0);
accounts.push(receiverAccount);
}
else
{
receiverAccount = accounts.find(account => account.name === transactions[i].to);
}
senderAccount.amount = senderAccount.amount - transactions[i].amount;
receiverAccount.amount = receiverAccount.amount + transactions[i].amount;
}
}
module.exports = createAccounts;