Advertisement
ErolKZ

Untitled

Oct 17th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function solve(arr) {
  2.  
  3.  
  4. let arr2 = [];
  5.  
  6.  
  7. for (let i = 0; i < arr.length; i++) {
  8.  
  9. let current = arr[i].split(' ');
  10.  
  11.  
  12.  
  13. if (current[2] === 'going!') {
  14.  
  15. if (!arr2.includes(current[0])) {
  16.  
  17. arr2.push(current[0]);
  18.  
  19. } else {
  20.  
  21. console.log(`${current[0]} is already in the list!`);
  22.  
  23. }
  24.  
  25. } else if (current[2] === 'not') {
  26.  
  27. if (arr2.includes(current[0])) {
  28.  
  29. arr2.splice(arr2.indexOf(current[0]), 1);
  30.  
  31. } else {
  32.  
  33. console.log(`${current[0]} is not in the list!`);
  34.  
  35. }
  36.  
  37. }
  38.  
  39.  
  40. }
  41.  
  42.  
  43. for (let i = 0; i < arr2.length; i++) {
  44.  
  45. console.log(arr2[i]);
  46.  
  47. }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement