Liliana797979

activation keys - final exam - fundamentals

Aug 4th, 2021
182
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.     //console.log(rawKeys);
  4.     let line = input.shift();
  5.     rawKeys = String(rawKeys);
  6.     while (line !== "Generate") {
  7.         let [command, mode, firstArgument, secondArgument] = line.split(">>>");
  8.         switch (command) {
  9.             case "Contains":
  10.                 let substring = mode;
  11.                 if (rawKeys.includes(substring)) {
  12.                     console.log(`${rawKeys} contains ${substring}`);
  13.                    
  14.                 } else {
  15.                     console.log(`Substring not found!`);
  16.                 }
  17.                 break;
  18.             case "Flip": {
  19.                 let startIndex = Number(firstArgument);
  20.                 let endIndex = Number(secondArgument);
  21.                 if (mode === "Upper")
  22.                 let substring = rawKeys.slice(startIndex, endIndex);
  23.                 rawKeys = rawKeys.replace(substring.substring.toUpperCase());
  24.                 console.log(rawKeys);
  25.            
  26.             } else {
  27.                 let substr = rawKeys.slice(startIndex, endIndex);
  28.                 rawKeys = rawKeys.replace(substr.substr.toLowerCase());
  29.                 console.log(rawKeys);
  30.             }
  31.        
  32.             break;
  33.            
  34.         }
  35.             case "Slice": {
  36.                 let startIndex = Number(firstArgument);
  37.                 let endIndex = Number(secondArgument);
  38.                 let cut = rawKeys.substring(startIndex, endIndex);
  39.                 rawKeys = rawKeys.replace(cut, "");
  40.                 console.log(rawKeys);
  41.                 break;
  42.             }
  43.    
  44.     }
  45.         line = input.shift();
  46.     console.log(`Your activation key is: ${rawKeys}`);
  47. }
  48.  
  49. activation((["abcdefghijklmnopqrstuvwxyz",
  50. "Slice>>>2>>>6",
  51. "Flip>>>Upper>>>3>>>14",
  52. "Flip>>>Lower>>>5>>>7",
  53. "Contains>>>def",
  54. "Contains>>>deF",
  55. "Generate"])
  56. );
Advertisement
Add Comment
Please, Sign In to add comment