Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function solve(input) {
  2. let friends = input[0].split(", ");
  3.  
  4. for (let i = 1; i < input.length; i++) {
  5. let [command, value, newName] = input[i].split(" ");
  6.  
  7. if (command === "Report") {
  8. break;
  9. } else if (command === "Blacklist") {
  10. if (friends.includes(value)) {
  11. let index = friends.indexOf(value);
  12. friends[index] = "Blacklisted";
  13. console.log(`${value} was blacklisted.`);
  14. } else {
  15. console.log(`${value} was not found.`);
  16. }
  17. } else if (command === "Error") {
  18. let userName = friends[value];
  19. if (userName !== "Blacklisted" && userName !== "Lost") {
  20. friends[value] = "Lost";
  21. console.log(`${userName} was lost due to an error.`);
  22. }
  23. } else if (command === "Change") {
  24. if (friends[value] !== undefined) {
  25. let currentName = friends[value];
  26. friends[value] = newName;
  27. console.log(`${currentName} changed his username to ${newName}.`);
  28. }
  29. }
  30. }
  31.  
  32. let blacklistArr = friends.filter(e => e === "Blacklisted");
  33. let lostArr = friends.filter(e => e === "Lost");
  34. console.log(`Blacklisted names: ${blacklistArr.length}`);
  35. console.log(`Lost names: ${lostArr.length}`);
  36. console.log(friends.join(" "));
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement