Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- input.pop();
- let str = input.shift();
- input.forEach(line => {
- command = line.split('>>>');
- let instruction = command[0];
- if(instruction === 'Contains'){
- let substring = command[1];
- if(str.includes(substring)){
- console.log(`${str} contains ${substring}.`)
- }
- else{
- console.log('Substring not found!')
- }
- }
- if(instruction === 'Flip'){
- let direction = command[1];
- let startIndex = command[2];
- let endIndex = command[3];
- let substring = str.substring(startIndex, endIndex);
- if(direction === 'Upper'){
- substring = substring.toUpperCase();
- }
- if(direction === 'Lower'){
- substring = substring.toLowerCase();
- }
- str = str.substring(0,startIndex) + substring + str.substring(endIndex);
- console.log(str);
- }
- if(instruction === 'Slice') {
- let startIndex = command[1];
- let endIndex = command[2];
- str = str.split('');
- str.splice(startIndex, endIndex - startIndex);
- str = str.join('');
- console.log(str);
- }
- })
- console.log(`Your activation key is: ${str}`)
- }
- solve([
- 'abcdefghijklmnopqrstuvwxyz',
- 'Slice>>>2>>>6',
- 'Flip>>>Upper>>>3>>>14',
- 'Flip>>>Lower>>>5>>>7',
- 'Contains>>>def',
- 'Contains>>>deF',
- 'Generate'
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement