Advertisement
Guest User

House party

a guest
Feb 17th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. function solve(arr) {
  2. let newArr = [];
  3.  
  4. for (let element of arr) {
  5. let command = element.split(' ');
  6. let name = command[0];
  7. if (command.length === 3) {
  8. if (newArr.includes(name)) {
  9. console.log(`${name} is already in the list!`);
  10. } else{
  11. newArr.push(name);
  12. }
  13. } else if (command.length === 4) {
  14. if (newArr.includes(name)) {
  15. newArr.filter(names => names !== name);
  16. } else{
  17. console.log(`${name} is not in the list!`);
  18. }
  19. }
  20. }
  21.  
  22. return newArr.join(`\n`)
  23. }
  24.  
  25. console.log(solve(['Allie is going!', 'George is going!', 'John is not going!', 'George is not going!']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement