AreWe

HouseParty (Petromir Logic)

Jun 12th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. houseParty = (input) => {
  2. let guests = [];
  3. while(input.length > 0) {
  4. let cmd = input.shift().split(' ');
  5. let index = guests.indexOf(cmd[0]);
  6.  
  7. if(index !== -1) {
  8. console.log(`${cmd[0]} is ${cmd[2] === 'going!' ? 'already' : 'not'} in the list!`);
  9. } else {
  10. if(cmd[2] === 'going!') {
  11. guests.push(cmd[0]);
  12. } else {
  13. guests.splice(index, 1);
  14. }
  15. }
  16. }
  17.  
  18. console.log(guests.join('\n'));
  19. };
Advertisement
Add Comment
Please, Sign In to add comment