Liliana797979

house party - fundamentals

Jun 24th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function houseParty(arr) {
  3.   let list = [];
  4.   let guestName = ''
  5.  
  6.   for (let i = 0; i < arr.length; i++) {
  7.       let line = arr[i].split(" ");
  8.       let name = line[0];
  9.       let command = line[2];
  10.           if (command !== 'not') {
  11.             if (list.includes(name) === true) {
  12.               console.log(`${name} is already in the list!`);
  13.               continue;
  14.           }
  15.           list.push(name);            
  16.           } else {
  17.             if (list.includes(name) === false) {
  18.               console.log(`${name} is not in the list!`);
  19.               continue;
  20.             }
  21.               list = list.filter(x => x!= name);
  22.           }
  23.   }
  24.   console.log(list.join('\n'));
  25. }
  26.  
  27. //houseParty(['Tom is going!', 'Annie is going!', 'Tom is going!', 'Garry is going!', 'Jerry is going!']);
  28. houseParty(['Allie is going!', 'George is going!', 'John is not going!', 'George is not going!'])
Advertisement
Add Comment
Please, Sign In to add comment