Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let activationKey = input.splice(0,1).toString();
- let commands = input.shift();
- while(commands !== 'Generate'){
- let separatedCommands = commands.split('>>>');
- if(separatedCommands[0] === 'Contains'){
- let neededSubstringg = separatedCommands[1];
- if(activationKey.includes(neededSubstringg)){
- console.log(`${activationKey} contains ${neededSubstringg}`);
- }else{
- console.log(`Substring not found!`);
- }
- } else if(separatedCommands[0] === 'Flip'){
- let startIndex = Number(separatedCommands[2]);
- let endIndex = Number(separatedCommands[3]);
- let neededChar = activationKey.substring(startIndex,endIndex);
- if(separatedCommands [1] === 'Upper'){
- let replaced = activationKey.substring(startIndex,endIndex).toUpperCase();
- activationKey = activationKey.replace(neededChar, replaced);
- console.log(activationKey);
- }else if(separatedCommands[1] === 'Lower'){
- let replaced = activationKey.substring(startIndex,endIndex).toLowerCase();
- activationKey = activationKey.replace(neededChar, replaced);
- console.log(activationKey);
- }
- }else if(separatedCommands[0] === 'Slice'){
- let startIndex = Number(separatedCommands[1]);
- let endIndex = Number(separatedCommands[2]);
- if((startIndex >= 0 && endIndex >= 0) && (startIndex < activationKey.length && activationKey.length > endIndex)){
- let slicedActivationKey = activationKey.substring(startIndex,endIndex);
- activationKey = activationKey.replace(slicedActivationKey,'');
- }
- console.log(activationKey);
- }
- commands = input.shift()
- }
- console.log(`Your activation key is: ${activationKey}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment