Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     input.pop();
  3.     let str = input.shift();
  4.     input.forEach(line => {
  5.         command = line.split('>>>');
  6.         let instruction = command[0];
  7.  
  8.         if(instruction === 'Contains'){
  9.             let substring = command[1];
  10.             if(str.includes(substring)){
  11.                 console.log(`${str} contains ${substring}.`)
  12.             }
  13.             else{
  14.                 console.log('Substring not found!')
  15.             }
  16.         }
  17.  
  18.         if(instruction === 'Flip'){
  19.             let direction = command[1];
  20.             let startIndex = command[2];
  21.             let endIndex = command[3];
  22.            
  23.             let substring = str.substring(startIndex, endIndex);
  24.             if(direction === 'Upper'){
  25.                 substring = substring.toUpperCase();
  26.             }
  27.  
  28.             if(direction === 'Lower'){
  29.                 substring = substring.toLowerCase();
  30.             }
  31.  
  32.             str = str.substring(0,startIndex) + substring + str.substring(endIndex);
  33.             console.log(str);
  34.         }
  35.  
  36.         if(instruction === 'Slice') {
  37.             let startIndex = command[1];
  38.             let endIndex = command[2];
  39.             str = str.split('');
  40.             str.splice(startIndex, endIndex - startIndex);
  41.             str = str.join('');
  42.             console.log(str);
  43.         }
  44.  
  45.     })
  46.     console.log(`Your activation key is: ${str}`)
  47. }
  48.  
  49. solve([
  50. 'abcdefghijklmnopqrstuvwxyz',
  51. 'Slice>>>2>>>6',
  52. 'Flip>>>Upper>>>3>>>14',
  53. 'Flip>>>Lower>>>5>>>7',
  54. 'Contains>>>def',
  55. 'Contains>>>deF',
  56. 'Generate'
  57.   ]
  58.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement