Advertisement
desito07

Activation Keys

Jul 17th, 2020
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let activationKey = input.shift();
  3.  
  4.   for (let i = 0; i < input.length; i++) {
  5.     let [command, firstArgument, secondArgument, thirdArgument] = input[
  6.       i
  7.     ].split(">>>");
  8.  
  9.     switch (command) {
  10.       case "Contains":
  11.         if (activationKey.includes(firstArgument)){
  12.           console.log(`${activationKey} contains ${firstArgument}`);
  13.         } else {
  14.           console.log("Substring not found!");
  15.         }
  16.         break;
  17.       case "Flip":
  18.         let temp1 = "";
  19.         let ind2 = Number(secondArgument);
  20.         let ind3 = Number(thirdArgument);
  21.         let replaced = activationKey.substring(ind2, ind3);
  22.         if (firstArgument === "Upper") {
  23.           temp1 = activationKey.substring(ind2, ind3).toUpperCase();
  24.           activationKey = activationKey.replace(replaced, temp1);
  25.           console.log(activationKey);
  26.         } else if (firstArgument === "Lower") {
  27.           temp1 = activationKey.substring(ind2, ind3).toLowerCase();
  28.           activationKey = activationKey.replace(replaced, temp1);
  29.           console.log(activationKey);
  30.         }
  31.         break;
  32.       case "Slice":
  33.         let temp = "";
  34.         index1 = Number(firstArgument);
  35.         index2 = Number(secondArgument);
  36.         if (
  37.           (index1 && index2) >= 0 &&
  38.           (index1 && index2) < activationKey.length
  39.         ) {
  40.           temp = activationKey.substring(index1, index2);
  41.           activationKey = activationKey.replace(temp, "");
  42.         }
  43.         console.log(activationKey);
  44.         break;
  45.       case "Generate":
  46.         break;
  47.     }
  48.   }
  49.   console.log(`Your activation key is: ${activationKey}`);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement