-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.3.js
44 lines (39 loc) · 1.11 KB
/
3.3.js
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
const make_account = (balance, pass) => {
let password = pass;
const withdraw = (amount) => {
if (balance >= amount) {
balance = balance - amount;
return balance
} else {
return "Insufficient Funds";
}
}
const deposit = (amount) => {
balance = balance + amount;
return balance;
}
const incorrectPassword = () =>{
return "Incorrect Password"
}
const dispatch = (pass, m) => {
if (m === "withdraw") {
if (pass === password) {
return withdraw
} else {
return incorrectPassword
}
} else if (m === "deposit") {
if (pass === password) {
return withdraw
} else {
return incorrectPassword
}
} else {
return console.log(m, "unknown request -- make_account")
}
}
return dispatch
}
const acc = make_account(100, "secret password");
console.log(acc("secret password", "withdraw")(40))
console.log(acc("some other password", "deposit")(40))