Advertisement
Lulunga

House Party

Jun 20th, 2019
109
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(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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement