-
Notifications
You must be signed in to change notification settings - Fork 28
/
draft.ts
40 lines (35 loc) · 1.6 KB
/
draft.ts
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
function input(): string { let X: any = input; X.L = X.L || require("fs").readFileSync(0).toString().split(/\r?\n/); return X.L.shift(); } // _TEST_ONLY_
// function input(): string { let X: any = input; X.P = X.P || require("readline-sync"); return X.P.question() } // _FREE_ONLY_
function write(text: any, endl="\n") { process.stdout.write("" + text + endl); }
export {};
function main() {
let bilheteria = new Bilheteria();
while (true) {
write("$", "");
let line = input();
write(line); // _TEST_ONLY_
let args = line.split(" ");
try {
if (args[0] === "end") {
break;
} else if (args[0] === "addPessoa") {
bilheteria.addPessoa(args[1], args[2] === "meia");
} else if (args[0] === "addEvento") {
bilheteria.addEvento(args[1], +args[2]);
} else if (args[0] === "pessoas") {
write("[" + bilheteria.getPessoas().map(p => p.toString()).sort().join(", ") + "]");
} else if (args[0] === "eventos") {
write("[" + bilheteria.getEventos().map(e => e.toString()).sort().join(", ") + "]");
} else if (args[0] === "vender") {
bilheteria.vender(args[1], args[2]);
} else if (args[0] === "vendas") {
write("[" + bilheteria.getVendas().map(v => v.toString()).join(", ") + "]");
} else {
write("fail: comando invalido");
}
} catch (e) {
write(e.message);
}
}
}
main();