Advertisement
silvana1303

house party

Apr 9th, 2021
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function  solve(arr){
  2.  
  3.     let list = [];
  4.  
  5.     for (let i = 0; i < arr.length; i++) {
  6.  
  7.         let command = arr[i].split(' ');
  8.  
  9.         if (command.length == 3){
  10.  
  11.             let name = command[0];
  12.  
  13.             if (list.includes(name)){
  14.                 console.log(`${name} is already in the list!`);
  15.             }
  16.             else{
  17.                 list.push(name);
  18.             }
  19.  
  20.         } else {
  21.  
  22.             let name = command[0];
  23.  
  24.             if (list.includes(name)){
  25.                 let index = list.indexOf(name);
  26.                 list.splice(index, 1);
  27.             }
  28.             else{
  29.                 console.log(`${name} is not in the list!`)
  30.             }
  31.         }
  32.     }
  33.  
  34.     for (const el of list) {
  35.         console.log(el);
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement