HristoYonkov

Friendlist

Oct 24th, 2021
763
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.     let friends = input.shift().split(', ');
  3.     let command = input.shift();
  4.  
  5.     while (command !== 'Report') {
  6.         let tokens = command.split(' ');
  7.  
  8.         if (tokens[0] === 'Blacklist') {
  9.             let name = tokens[1];
  10.             if(friends.includes(name)) {
  11.                 let indexOf = friends.indexOf(name);
  12.                 console.log(`${name} was blacklisted.`);
  13.                 friends[indexOf] = 'Blacklisted';
  14.             } else {
  15.                 console.log(`${name} was not found.`);
  16.             }
  17.  
  18.         } else if (tokens[0] === 'Error') {
  19.             let index = Number(tokens[1]);
  20.             if (friends[index] !== undefined && friends[index] !== 'Blacklisted' && friends[index] !== 'Lost') {
  21.                 console.log(`${friends[index]} was lost due to an error.`);
  22.                 friends[index] = 'Lost';
  23.             }
  24.  
  25.         } else if (tokens[0] === 'Change') {
  26.             let index = Number(tokens[1]);
  27.             let newName = tokens[2];
  28.  
  29.             if (friends[index] !== undefined) {
  30.                 console.log(`${friends[index]} changed his username to ${newName}.`);
  31.                 friends[index] = newName;
  32.             }
  33.         }
  34.  
  35.         command = input.shift();
  36.     }
  37.  
  38.     let BlCount = 0;
  39.     let lost = 0;
  40.  
  41.     for (let name of friends) {
  42.         if (name === 'Blacklisted') {
  43.             BlCount++;
  44.         } else if (name === 'Lost') {
  45.             lost++;
  46.         }
  47.     }
  48.  
  49.     console.log(`Blacklisted names: ${BlCount}`);
  50.     console.log(`Lost names: ${lost}`);
  51.     console.log(friends.join(' '));
  52.  
  53.  
  54. }
RAW Paste Data