@@ -9,27 +9,27 @@ class AccountCommand {
99}
1010
1111class BankAccount {
12+ static accounts = new Map ( ) ;
13+
1214 constructor ( name ) {
1315 this . name = name ;
1416 this . balance = 0 ;
15- BankAccount . collection . set ( name , this ) ;
17+ BankAccount . accounts . set ( name , this ) ;
1618 }
1719}
1820
19- BankAccount . collection = new Map ( ) ;
20-
21- const operations = {
22- Withdraw : ( command ) => {
23- const account = BankAccount . collection . get ( command . account ) ;
21+ const OPERATIONS = {
22+ withdraw : ( command ) => {
23+ const account = BankAccount . accounts . get ( command . account ) ;
2424 account . balance -= command . amount ;
2525 } ,
26- Income : ( command ) => {
27- const account = BankAccount . collection . get ( command . account ) ;
26+ income : ( command ) => {
27+ const account = BankAccount . accounts . get ( command . account ) ;
2828 account . balance += command . amount ;
2929 } ,
30- Allowed : ( command ) => {
31- if ( command . operation === 'Income ' ) return true ;
32- const account = BankAccount . collection . get ( command . account ) ;
30+ allowed : ( command ) => {
31+ if ( command . operation === 'income ' ) return true ;
32+ const account = BankAccount . accounts . get ( command . account ) ;
3333 return account . balance >= command . amount ;
3434 } ,
3535} ;
@@ -40,17 +40,17 @@ class Bank {
4040 }
4141
4242 operation ( account , amount ) {
43- const operation = amount < 0 ? 'Withdraw ' : 'Income ' ;
44- const execute = operations [ operation ] ;
43+ const operation = amount < 0 ? 'withdraw ' : 'income ' ;
44+ const execute = OPERATIONS [ operation ] ;
4545 const command = new AccountCommand (
4646 operation ,
4747 account . name ,
4848 Math . abs ( amount ) ,
4949 ) ;
50- const check = operations . Allowed ;
50+ const check = OPERATIONS . allowed ;
5151 const allowed = check ( command ) ;
5252 if ( ! allowed ) {
53- const target = BankAccount . collection . get ( command . account ) ;
53+ const target = BankAccount . accounts . get ( command . account ) ;
5454 const msg = [
5555 'Command is not allowed' ,
5656 'do ' + JSON . stringify ( command ) ,
@@ -75,7 +75,7 @@ bank.operation(account1, 1000);
7575bank . operation ( account1 , - 50 ) ;
7676const account2 = new BankAccount ( 'Antoninus Pius' ) ;
7777bank . operation ( account2 , 500 ) ;
78- bank . operation ( account2 , - 10000 ) ;
78+ bank . operation ( account2 , - 10000 ) ; // -10000
7979bank . operation ( account2 , 150 ) ;
8080bank . showOperations ( ) ;
8181console . table ( [ account1 , account2 ] ) ;
0 commit comments