Advertisement
TZinovieva

Party Time JS Fundamentals

Mar 4th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let guests = {
  3.     vip: [],
  4.     regular: []
  5.   };
  6.   let inParty = false;
  7.  
  8.   for (let i = 0; i < input.length; i++) {
  9.     let current = input[i];
  10.     if (current === "PARTY") {
  11.       inParty = true;
  12.       continue;
  13.     }
  14.     if (!inParty) {
  15.       if (isNaN(current[0])) {
  16.         guests.regular.push(current);
  17.       } else {
  18.         guests.vip.push(current);
  19.       }
  20.     } else {
  21.       if (isNaN(current[0])) {
  22.         if (guests.regular.includes(current)) {
  23.           guests.regular.splice(guests.regular.indexOf(current), 1);
  24.         }
  25.       } else {
  26.         if (guests.vip.includes(current)) {
  27.           guests.vip.splice(guests.vip.indexOf(current), 1);
  28.         }
  29.       }
  30.     }
  31.   }
  32.  
  33.   let remainingGuestsCount = guests.vip.length + guests.regular.length;
  34.   console.log(remainingGuestsCount);
  35.   console.log(guests.vip.join('\n'));
  36.   console.log(guests.regular.join('\n'));
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement