Ivankooo1

Friend List

Jan 11th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function friendList(input){
  2.    let listsOfFriends = input.shift().split(', ');
  3.    let blackListCount = 0;
  4.    let lostListCount = 0;
  5.    for(let i = 0;i < input.length;i++){
  6.      let commands = input[i].split(' ');
  7.      let command = commands[0];
  8.    
  9.  
  10.      if(command === 'Report'){
  11.        break;
  12.      }
  13.  
  14.      if(command === 'Blacklist'){
  15.         let names = commands[1];
  16.  
  17.         if(listsOfFriends.includes(names)){
  18.           let index = listsOfFriends.indexOf(names);
  19.           listsOfFriends.splice(index,1,'Blacklisted');
  20.           console.log(`${names} was blacklisted.`);
  21.           blackListCount++;
  22.      
  23.         }else{
  24.           console.log(`${names} was not found.`)
  25.         }
  26.      }
  27.  
  28.      if(command === 'Error'){
  29.         let nameIndex = listsOfFriends[Number(commands[1])];
  30.  
  31.         if(nameIndex !== 'Blacklisted' && nameIndex !== 'Lost'){
  32.           let index = listsOfFriends.indexOf(nameIndex);
  33.           listsOfFriends.splice(index,1,'Lost');
  34.           console.log(`${nameIndex} was lost due to an error.`);
  35.           lostListCount++;
  36.         }
  37.      }
  38.  
  39.      if(command === 'Change'){
  40.        let index = Number(commands[1]);
  41.        let newName = commands[2];
  42.        let currentName = listsOfFriends[index];
  43.  
  44.        if(listsOfFriends.length >= index && index >= 0){
  45.          listsOfFriends.splice(index,1,newName);
  46.          console.log(`${currentName} changed his username to ${newName}.`)
  47.        }
  48.      }
  49.  
  50.    }
  51.    console.log(`Blacklisted names: ${blackListCount}`);
  52.    console.log(`Lost names: ${lostListCount}`);
  53.    console.log(listsOfFriends.join(' '));
  54. }
  55.  
  56. // friendList([
  57.  
  58. // 'Mike, John, Eddie',
  59. // 'Blacklist Mike',
  60. // 'Error 0',
  61. // 'Error 1',
  62. // 'Change 2 Mike123',
  63. // 'Report'
  64.  
  65. // ])
  66.  
  67. friendList([
  68.   'Mike, John, Eddie, William',
  69.   'Error 3',
  70.   'Error 3',
  71.   'Change 0 Mike123',
  72.   'Blacklist Eddie',
  73.   'Report'
  74. ]);
Advertisement
Add Comment
Please, Sign In to add comment