Todorov_Stanimir

04. Party Time with Map

Jul 10th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function partyTime(input) {
  2.     let guests = new Map();
  3.     guests.set('VIP', []);
  4.     guests.set('regular', []);
  5.     input.slice(0, input.indexOf('PARTY')).forEach((guest) => {
  6.         (Number(guest[0]))
  7.             ? guests.get('VIP').push(guest)
  8.             : guests.get('regular').push(guest)
  9.     });
  10.  
  11.     let cameGuests = input.slice(input.indexOf('PARTY') + 1, input.length);
  12.  
  13.     cameGuests.forEach(guest => {
  14.         (Number(guest[0]))
  15.             ? guests.get('VIP').splice(guests.get('VIP').indexOf(guest), 1)
  16.             : guests.get('regular').splice(guests.get('regular').indexOf(guest), 1)
  17.     });
  18.  
  19.     let result = guests.get('VIP').concat(guests.get('regular'));
  20.     console.log(result.length);
  21.     result.forEach((guest) => console.log(guest));
  22. }
  23. partyTime(['9NoBUajQ',
  24.     'Ce8vwPmE',
  25.     'SVQXQCbc',
  26.     'tSzE5t0p',
  27.     '7IK9Yo0h',
  28.     'PARTY',
  29.     '9NoBUajQ',
  30.     'Ce8vwPmE',
  31.     'SVQXQCbc',
  32. ]);
  33. partyTime(['m8rfQBvl',
  34.     'fc1oZCE0',
  35.     'UgffRkOn',
  36.     '7ugX7bm0',
  37.     '9CQBGUeJ',
  38.     '2FQZT3uC',
  39.     'dziNz78I',
  40.     'mdSGyQCJ',
  41.     'LjcVpmDL',
  42.     'fPXNHpm1',
  43.     'HTTbwRmM',
  44.     'B5yTkMQi',
  45.     '8N0FThqG',
  46.     'xys2FYzn',
  47.     'MDzcM9ZK',
  48.     'PARTY',
  49.     '2FQZT3uC',
  50.     'dziNz78I',
  51.     'mdSGyQCJ',
  52.     'LjcVpmDL',
  53.     'fPXNHpm1',
  54.     'HTTbwRmM',
  55.     'B5yTkMQi',
  56.     '8N0FThqG',
  57.     'm8rfQBvl',
  58.     'fc1oZCE0',
  59.     'UgffRkOn',
  60.     '7ugX7bm0',
  61.     '9CQBGUeJ'
  62. ])
Advertisement
Add Comment
Please, Sign In to add comment