Pijomir

Party Time

Nov 5th, 2023
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function managePartyList(input) {
  2.     let partyList = {'VIP': [], 'regular': []};
  3.     while (input.length > 0) {
  4.         let entry = input.shift();
  5.         let typeOfGuest = entry[0];
  6.         if (entry === 'PARTY') {
  7.             break;
  8.         } else {
  9.             isNaN(Number(typeOfGuest)) ? partyList.regular.push(entry) : partyList.VIP.push(entry);
  10.         }
  11.     }
  12.    
  13.     for (let guest of input) {
  14.         if (partyList.VIP.includes(guest)) {
  15.             let index = partyList.VIP.indexOf(guest);
  16.             partyList.VIP.splice(index, 1);
  17.         } else if (partyList.regular.includes(guest)) {
  18.             let index = partyList.regular.indexOf(guest);
  19.             partyList.regular.splice(index, 1);
  20.         }
  21.     }
  22.  
  23.     console.log(partyList.VIP.length + partyList.regular.length);
  24.     partyList.VIP.forEach(a => console.log(a));
  25.     partyList.regular.forEach(a => console.log(a));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment