1
/**
2
* @param {number[]} balance
3
*/
4
var Bank = function (balance) {
5
this.arr = balance;
6
};
7

8
/**
9
* @param {number} account1
10
* @param {number} account2
11
* @param {number} money
12
* @return {boolean}
13
*/
14
Bank.prototype.transfer = function (account1, account2, money) {
15
if (
16
this.arr[account1 - 1] >= money &&
17
this.arr.length >= account1 &&
18
this.arr.length >= account2
19
) {
20
this.arr[account1 - 1] -= money;
21
this.arr[account2 - 1] += money;
22
return true;
23
}
24
return false;
25
};
26

27
/**
28
* @param {number} account
29
* @param {number} money
30
* @return {boolean}
31
*/
32
Bank.prototype.deposit = function (account, money) {
33
if (this.arr.length >= account) {
34
this.arr[account - 1] += money;
35
return true;
36
}
37
return false;
38
};
39

40
/**
41
* @param {number} account
42
* @param {number} money
43
* @return {boolean}
44
*/
45
Bank.prototype.withdraw = function (account, money) {
46
if (this.arr.length >= account && this.arr[account - 1] >= money) {
47
this.arr[account - 1] -= money;
48
return true;
49
}
50
return false;
51
};
52

53
/**
54
* Your Bank object will be instantiated and called as such:
55
* var obj = new Bank(balance)
56
* var param_1 = obj.transfer(account1,account2,money)
57
* var param_2 = obj.deposit(account,money)
58
* var param_3 = obj.withdraw(account,money)
59
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0