Advertisement
braveheart1989

SAME SHIT

Dec 16th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  function solve(input) {
  2.  
  3.     let towns = {};
  4.     let data = [];
  5.     let arr = [];
  6.     let isLanded = false;
  7.     for (let line of input) {
  8.         let planeId = line.split(' ')[0];
  9.         let town = line.split(' ')[1];
  10.         let passengersCount = Number(line.split(' ')[2]);
  11.         let action = line.split(' ')[3];
  12.  
  13.  
  14.         if (!towns[town] && action == 'land') {
  15.             data.push(planeId);
  16.             isLanded = true;
  17.         }
  18.         if (action == 'depart') {
  19.             isLanded = false;
  20.         }
  21.  
  22.         if (!towns[town]) {
  23.             towns[town] = {
  24.                 arrivals: 0,
  25.                 departures: 0,
  26.                 planesData: [],
  27.                 isLanded: isLanded
  28.             };
  29.         }
  30.  
  31.         if (action == 'land') {
  32.             towns[town].arrivals += passengersCount
  33.         }
  34.         else {
  35.             towns[town].departures += passengersCount
  36.         }
  37.         if (action == 'land') {
  38.  
  39.         }
  40.         towns[town].planesData.push(planeId);
  41.  
  42.         arr.push()
  43.     }
  44.  
  45.     data.sort((a, b) => {
  46.         return a[0].localeCompare(b[0])
  47.     });
  48.  
  49.  
  50.  
  51.  
  52.     console.log(`Planes left:`);
  53.     for (let town of data) {
  54.         console.log(`- ${town}`);
  55.     }
  56.  
  57.     // console.log(towns);
  58.     //  for (let key of data) {
  59.     //       // Object.keys(data[key].arrivals).sort(function(a,b){return key[a]-key[b]})
  60.     //      console.log(key);
  61.     //  }
  62.      // console.log(data);
  63.  
  64.  
  65.     for (let line in towns) {
  66.         if (towns[line].isLanded == true) {
  67.             console.log(`${line}`);
  68.             console.log(`Arrivals: ${towns[line].arrivals}`);
  69.             console.log(`Departures: ${towns[line].departures}`);
  70.             console.log("Planes:");
  71.             console.log(`-- ${towns[line].planesData.join('\n-- ')}`);
  72.         }
  73.     }
  74.  
  75.  
  76. }
  77. solve(
  78.     [
  79.         "Boeing474 Madrid 300 land",
  80.         "AirForceOne WashingtonDC 178 land",
  81.         "Airbus London 265 depart",
  82.         "ATR72 WashingtonDC 272 land",
  83.         "ATR72 Madrid 135 depart"
  84.     ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement