Advertisement
miroLLL

Party Time

Jul 10th, 2020
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(input) {
  2.  
  3.     let partyIndex = input.indexOf("PARTY");
  4.     let guestList = input.slice(0, partyIndex);
  5.     let commingGuests = input.slice(partyIndex + 1);
  6.  
  7.     let reservationList = generateGuestList(guestList);
  8.  
  9.     commingGuests.forEach((guest) => {
  10.         let status = checkForVIP(guest);
  11.         let correctList = status ? "vip" : 'regular';
  12.  
  13.         let currentGuest = reservationList[correctList].find((o) => o.guest === guest);
  14.  
  15.         if (status && currentGuest) {
  16.             currentGuest.isHere = true;
  17.         } else if (!status && currentGuest) {
  18.             currentGuest.isHere = true;
  19.         }
  20.     });
  21.  
  22.     let vipGuests = reservationList.vip.filter((o) => o.isHere === false)
  23.     let regularGuests = reservationList.regular.filter((o) => o.isHere === false)
  24.  
  25.     console.log(vipGuests.length + regularGuests.length);
  26.  
  27.     vipGuests.concat(regularGuests).forEach((guest) => console.log(guest.guest))
  28.  
  29.     function generateGuestList(guests) {
  30.         let obj = {
  31.             vip: [],
  32.             regular: []
  33.         };
  34.  
  35.         guests.forEach((guest) => {
  36.             let guestObj = { guest, isHere: false }
  37.  
  38.             if (checkForVIP(guest)) {
  39.                 obj.vip.push(guestObj);
  40.             } else {
  41.                 obj.regular.push(guestObj);
  42.             }
  43.         });
  44.  
  45.         return obj;
  46.     }
  47.  
  48.     function checkForVIP(guest) {
  49.         return !isNaN(Number(guest[0]));
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement