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] === 'Slice'){
- let newStr = ''
- 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);
- newStr = activationKey.replace(slicedActivationKey,'');
- activationKey = newStr;
- console.log(activationKey);
- }
- }else if(separatedCommands[0] === 'Flip'){
- if(separatedCommands [1] === 'Upper'){
- let startIndex = Number(separatedCommands[2]);
- let endIndex = Number(separatedCommands[3]);
- let neededChar = activationKey.substring(startIndex,endIndex);
- let changedneededChar = neededChar.toUpperCase();
- let replaced = activationKey.replace(neededChar,changedneededChar)
- activationKey = replaced;
- console.log(activationKey);
- }else if(separatedCommands[1] === 'Lower'){
- let startIndex = Number(separatedCommands[2]);
- let endIndex = Number(separatedCommands[3]);
- let neededChar = activationKey.substring(startIndex,endIndex);
- let changedneededChar = neededChar.toLowerCase();
- let replaced = activationKey.replace(neededChar,changedneededChar);
- activationKey = replaced;
- console.log(activationKey);
- }
- }else if(separatedCommands[0] === 'Contains'){
- let neededSubstringg = separatedCommands[1];
- if(activationKey.includes(neededSubstringg)){
- console.log(`${activationKey} contains ${neededSubstringg}.`);
- }else{
- console.log(`Substring not found!`);
- }
- }
- commands = input.shift()
- }
- console.log(`Your activation key is: ${newStr}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment