-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
27 lines (23 loc) · 837 Bytes
/
index.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
const fs = require('fs');
const util = require('util');
const { Red, Yellow } = require('./models/Airline');
const getFares = async () => {
const departure = 'CNX';
const destination = 'DMK';
const redAirline = new Red('AirRed');
const yellowAirline = new Yellow('YellowBird');
try {
const getFarePromise = [redAirline, yellowAirline].map((airline) =>
airline.getFares(departure, destination),
);
const fares = await Promise.all(getFarePromise);
const results = fares.flat();
const filtered = results.filter((fare) => fare.isCheaperThan(1000, 2));
const writeFile = util.promisify(fs.writeFile);
await writeFile('results.json', JSON.stringify(filtered));
console.log(`Saved ${filtered.length} flights to results.json`);
} catch (error) {
console.error(error);
}
};
getFares();