svephoto

Activation Keys [JavaScript]

Aug 4th, 2021 (edited)
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function activation(input) {
  2.     let rawKeys = input.shift();
  3.     let line = input.shift();
  4.  
  5.     while (line !== "Generate") {
  6.         let tokens = line.split(">>>");
  7.  
  8.         let command = tokens[0];
  9.        
  10.         switch (command) {
  11.             case "Contains": {
  12.                 let subString = tokens[1];
  13.  
  14.                 if (rawKeys.includes(subString)) {
  15.                     console.log(`${rawKeys} contains ${subString}`);                    
  16.                 } else {
  17.                     console.log(`Substring not found!`);
  18.                 }
  19.  
  20.                 break;
  21.             }
  22.             case "Flip": {
  23.                 let currentCommand = tokens[1];
  24.                 let startIndex = Number(tokens[2]);
  25.                 let endIndex = Number(tokens[3]);
  26.  
  27.                 let subString = rawKeys.slice(startIndex, endIndex);
  28.                
  29.                 if (currentCommand === "Upper") {
  30.                     rawKeys = rawKeys.replace(subString, subString.toUpperCase());
  31.                 } else {
  32.                     rawKeys = rawKeys.replace(subString, subString.toLowerCase());
  33.                 }
  34.  
  35.                 console.log(rawKeys);
  36.        
  37.                 break;            
  38.             }
  39.             case "Slice": {
  40.                 let startIndex = Number(tokens[1]);
  41.                 let endIndex = Number(tokens[2]);
  42.  
  43.                 let cut = rawKeys.substring(startIndex, endIndex);
  44.                 rawKeys = rawKeys.split(cut).join("");
  45.                
  46.                 console.log(rawKeys);
  47.                
  48.                 break;
  49.             }
  50.    
  51.         }
  52.  
  53.         line = input.shift();
  54.     }
  55.  
  56.     console.log(`Your activation key is: ${rawKeys}`);
  57. }
  58.  
Add Comment
Please, Sign In to add comment