Advertisement
PowerCell46

House party JS

Nov 30th, 2022
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function houseParty(array) {
  2.  
  3.     let printedList = [];
  4.  
  5.     for (let index = 0; index < Number(array.length); index++) {
  6.         let currentLine = array[index];
  7.         currentLine = currentLine.split(" ");
  8.  
  9.         if (!printedList.includes(currentLine[0]) && currentLine[1] === "is" && currentLine[2] === "going!") {
  10.             printedList.push(currentLine[0]);
  11.             continue;
  12.         }
  13.         if (printedList.includes(currentLine[0]) && currentLine[1] === "is" && currentLine[2] === "going!") {
  14.             console.log(`${currentLine[0]} is already in the list!`);
  15.             continue;
  16.         }
  17.         if (!printedList.includes(currentLine[0]) && currentLine[1] === "is" && currentLine[2] === "not" && currentLine[3] === "going!") {
  18.             console.log(`${currentLine[0]} is not in the list!`);
  19.             continue;
  20.         }
  21.         if (printedList.includes(currentLine[0]) && currentLine[1] === "is" && currentLine[2] === "not" && currentLine[3] === "going!") {
  22.             let index = printedList.indexOf(currentLine[0]);
  23.             printedList.splice(index, 1);
  24.             continue;
  25.         }
  26.  
  27.     }
  28.  
  29.     console.log(printedList.join(`\n`));
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement