Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let towns = {};
- let data = [];
- let arr = [];
- let isLanded = false;
- for (let line of input) {
- let planeId = line.split(' ')[0];
- let town = line.split(' ')[1];
- let passengersCount = Number(line.split(' ')[2]);
- let action = line.split(' ')[3];
- if (!towns[town] && action == 'land') {
- data.push(planeId);
- isLanded = true;
- }
- if (action == 'depart') {
- isLanded = false;
- }
- if (!towns[town]) {
- towns[town] = {
- arrivals: 0,
- departures: 0,
- planesData: [],
- isLanded: isLanded
- };
- }
- if (action == 'land') {
- towns[town].arrivals += passengersCount
- }
- else {
- towns[town].departures += passengersCount
- }
- if (action == 'land') {
- }
- towns[town].planesData.push(planeId);
- arr.push()
- }
- data.sort((a, b) => {
- return a[0].localeCompare(b[0])
- });
- console.log(`Planes left:`);
- for (let town of data) {
- console.log(`- ${town}`);
- }
- // console.log(towns);
- // for (let key of data) {
- // // Object.keys(data[key].arrivals).sort(function(a,b){return key[a]-key[b]})
- // console.log(key);
- // }
- // console.log(data);
- for (let line in towns) {
- if (towns[line].isLanded == true) {
- console.log(`${line}`);
- console.log(`Arrivals: ${towns[line].arrivals}`);
- console.log(`Departures: ${towns[line].departures}`);
- console.log("Planes:");
- console.log(`-- ${towns[line].planesData.join('\n-- ')}`);
- }
- }
- }
- solve(
- [
- "Boeing474 Madrid 300 land",
- "AirForceOne WashingtonDC 178 land",
- "Airbus London 265 depart",
- "ATR72 WashingtonDC 272 land",
- "ATR72 Madrid 135 depart"
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement