SHARE
TWEET

Untitled

a guest Oct 9th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map = {
  2.     tkt1: {
  3.         departure: 'Los Angeles',
  4.         arrival: 'San Francisco'
  5.     },
  6.     tkt2: {
  7.         departure: 'San Francisco',
  8.         arrival: 'New York'
  9.     },
  10.     tkt3: {
  11.         departure: 'Moscow',
  12.         arrival: 'Mali'
  13.     },
  14.     tkt4: {
  15.         departure: 'Barcelona',
  16.         arrival: 'Moscow'
  17.     },
  18.     tkt5: {
  19.         departure: 'New York',
  20.         arrival: 'Barcelona'
  21.     }
  22. };
  23.  
  24. findDepartureArrival = function(map) {
  25.     var hashMap = {};
  26.  
  27.     for (var tkt in map) {
  28.         var depart = map[tkt].departure;
  29.         var arriv = map[tkt].arrival;
  30.  
  31.         if (!(depart in hashMap))
  32.             hashMap[depart] = -1;
  33.         else
  34.             hashMap[depart] = hashMap[depart] - 1;
  35.  
  36.         if (!(arriv in hashMap))
  37.             hashMap[arriv] = 1;
  38.         else
  39.             hashMap[arriv] = hashMap[arriv] + 1;
  40.     }
  41.     return hashMap;
  42. }
  43.  
  44. console.log(findDepartureArrival(map));
  45. /*Output
  46. { 'Los Angeles': -1,
  47.   'San Francisco': 0,
  48.   'New York': 0,
  49.   Moscow: 0,
  50.   Mali: 1,
  51.   Barcelona: 0 }*/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top