SHOW:
|
|
- or go back to the newest paste.
| 1 | function solve(input) {
| |
| 2 | - | |
| 2 | + | |
| 3 | - | let activationKey = input.splice(0,1).toString() |
| 3 | + | let activationKey = input.splice(0,1).toString(); |
| 4 | - | let commands = input.shift(); |
| 4 | + | let commands = input.shift(); |
| 5 | - | |
| 5 | + | while(commands !== 'Generate'){
|
| 6 | - | while(commands !== 'Generate'){
|
| 6 | + | |
| 7 | - | |
| 7 | + | let separatedCommands = commands.split('>>>');
|
| 8 | - | let separatedCommands = commands.split('>>>');
|
| 8 | + | if(separatedCommands[0] === 'Contains'){
|
| 9 | - | if(separatedCommands[0] === 'Slice'){
|
| 9 | + | let neededSubstringg = separatedCommands[1]; |
| 10 | - | let newStr = '' |
| 10 | + | if(activationKey.includes(neededSubstringg)){
|
| 11 | - | let startIndex = Number(separatedCommands[1]); |
| 11 | + | console.log(`${activationKey} contains ${neededSubstringg}`);
|
| 12 | - | let endIndex = Number(separatedCommands[2]); |
| 12 | + | }else{
|
| 13 | - | if((startIndex >= 0 && endIndex >= 0) && (startIndex < activationKey.length && activationKey.length > endIndex)){
|
| 13 | + | console.log(`Substring not found!`); |
| 14 | - | let slicedActivationKey = activationKey.substring(startIndex,endIndex); |
| 14 | + | } |
| 15 | - | newStr = activationKey.replace(slicedActivationKey,''); |
| 15 | + | } else if(separatedCommands[0] === 'Flip'){
|
| 16 | - | activationKey = newStr; |
| 16 | + | |
| 17 | - | console.log(activationKey); |
| 17 | + | |
| 18 | - | } |
| 18 | + | |
| 19 | - | }else if(separatedCommands[0] === 'Flip'){
|
| 19 | + | if(separatedCommands [1] === 'Upper'){
|
| 20 | - | 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 changedneededChar = neededChar.toUpperCase(); |
| 24 | + | let replaced = activationKey.substring(startIndex,endIndex).toLowerCase(); |
| 25 | - | let replaced = activationKey.replace(neededChar,changedneededChar) |
| 25 | + | activationKey = activationKey.replace(neededChar, replaced); |
| 26 | - | activationKey = replaced; |
| 26 | + | console.log(activationKey); |
| 27 | - | console.log(activationKey); |
| 27 | + | } |
| 28 | - | }else if(separatedCommands[1] === 'Lower'){
|
| 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 changedneededChar = neededChar.toLowerCase(); |
| 32 | + | let slicedActivationKey = activationKey.substring(startIndex,endIndex); |
| 33 | - | let replaced = activationKey.replace(neededChar,changedneededChar); |
| 33 | + | activationKey = activationKey.replace(slicedActivationKey,''); |
| 34 | - | activationKey = replaced; |
| 34 | + | } |
| 35 | - | console.log(activationKey); |
| 35 | + | console.log(activationKey); |
| 36 | - | } |
| 36 | + | } |
| 37 | - | }else if(separatedCommands[0] === 'Contains'){
|
| 37 | + | commands = input.shift() |
| 38 | - | let neededSubstringg = separatedCommands[1]; |
| 38 | + | } |
| 39 | - | if(activationKey.includes(neededSubstringg)){
|
| 39 | + | |
| 40 | - | console.log(`${activationKey} contains ${neededSubstringg}.`);
|
| 40 | + | console.log(`Your activation key is: ${activationKey}`);
|
| 41 | - | }else{
|
| 41 | + | |
| 42 | - | console.log(`Substring not found!`); |
| 42 | + | } |