-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainMerger.js
48 lines (42 loc) · 1.13 KB
/
trainMerger.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
47
48
module.exports = class TrainAB {
constructor(dataInput) {
this.dataInput = dataInput;
this.station_after_HYB = {
HYB: 0,
NGP: 400,
ITJ: 700,
BPL: 800,
AGA: 2500,
NDL: 2700,
PTA: 3800,
NJP: 4200,
GHY: 4700,
};
this.DeptTrain = [];
}
processInput(input, type) {
const arrivalLabels = ['ARRIVAL', `TRAIN_${type}`, 'ENGINE'];
const filteredStations = [];
const tempBoggie = [];
for (let i = 2; i < input.length; i++) {
const station = input[i].trim();
if (this.station_after_HYB.hasOwnProperty(station)) {
filteredStations.push(station);
tempBoggie.push({
name: station,
id: this.station_after_HYB[station],
});
}
}
const boggieList = arrivalLabels.concat(filteredStations);
const boggie = boggieList.join(' ');
console.log(boggie);
return tempBoggie;
}
TrainA(input) {
return this.processInput(input, 'A');
}
TrainB(input) {
return this.processInput(input, 'B');
}
};