-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
46 lines (38 loc) · 894 Bytes
/
main.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
45
46
const fs = require("fs");
class Command {
constructor(name, params) {
this.name = name;
this.params = params;
}
}
function main() {
const filename = "input.txt";
const commands = getCommandsFromFileName(filename);
commands.forEach(command => {
switch (command.name) {
case "create_hotel": {
const [floor, roomPerFloor] = command.params;
return;
}
default:
return;
}
});
}
function getCommandsFromFileName(fileName) {
const file = fs.readFileSync(fileName, "utf-8");
return file
.split("\n")
.map(line => line.split(" "))
.map(
([commandName, ...params]) =>
new Command(
commandName,
params.map(param => {
const parsedParam = parseInt(param, 10);
return Number.isNaN(parsedParam) ? param : parsedParam;
})
)
);
}
main();