SHARE
TWEET

House Party

Lulunga Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.    let list = [];
  3.  
  4.    for (let line of input) {
  5.        let tokens = line.split(' ');
  6.        let name = tokens[0];
  7.        if (tokens.length===3) {
  8.            let isIncluded = list.includes(name);
  9.            if (isIncluded) {
  10.                console.log(`${name} is already in the list!`);
  11.            } else {
  12.                list.push(name);
  13.            }
  14.        } else {
  15.             let indexOfPerson = list.indexOf(name);
  16.             if(indexOfPerson===-1){
  17.                 console.log(`${name} is not in the list!`);
  18.             } else {
  19.                 list.splice(indexOfPerson, 1);
  20.             }
  21.        }
  22.    }
  23.    console.log(list.join('\n'));
  24. }
  25.  
  26. //Write a function that keeps track of guests that are going to a house party.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top