desito07

Activation Keys

Aug 1st, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let activationKey = input.splice(0,1).toString();
  4.     let commands = input.shift();    
  5.     while(commands !== 'Generate'){
  6.      
  7.      let separatedCommands = commands.split('>>>');
  8.      if(separatedCommands[0] === 'Contains'){
  9.         let neededSubstringg = separatedCommands[1];
  10.         if(activationKey.includes(neededSubstringg)){
  11.             console.log(`${activationKey} contains ${neededSubstringg}`);  
  12.         }else{
  13.             console.log(`Substring not found!`);    
  14.         }
  15.     } else if(separatedCommands[0] === 'Flip'){
  16.         let startIndex = Number(separatedCommands[2]);
  17.         let endIndex = Number(separatedCommands[3]);
  18.         let neededChar =  activationKey.substring(startIndex,endIndex);
  19.          if(separatedCommands [1] === 'Upper'){
  20.             let replaced = activationKey.substring(startIndex,endIndex).toUpperCase();
  21.             activationKey = activationKey.replace(neededChar, replaced);
  22.             console.log(activationKey);    
  23.          }else if(separatedCommands[1] === 'Lower'){            
  24.             let replaced = activationKey.substring(startIndex,endIndex).toLowerCase();
  25.             activationKey = activationKey.replace(neededChar, replaced);
  26.             console.log(activationKey);
  27.          }
  28.      }else if(separatedCommands[0] === 'Slice'){        
  29.          let startIndex = Number(separatedCommands[1]);
  30.          let endIndex = Number(separatedCommands[2]);
  31.          if((startIndex >= 0 && endIndex >= 0) && (startIndex < activationKey.length && activationKey.length > endIndex)){
  32.      let slicedActivationKey = activationKey.substring(startIndex,endIndex);
  33.      activationKey = activationKey.replace(slicedActivationKey,'');        
  34.          }
  35.          console.log(activationKey);
  36.     }
  37.     commands = input.shift()
  38.     }
  39.      
  40.     console.log(`Your activation key is: ${activationKey}`);
  41.      
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment