kstoyanov

01. Activation Keys js exam

Aug 12th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   let rawKey = args.shift();
  3.  
  4.  
  5.   let inputLine = args.shift();
  6.  
  7.   while (inputLine !== 'Generate') {
  8.     const [command, arg1, arg2, arg3] = inputLine.split('>>>');
  9.  
  10.  
  11.     switch (command) {
  12.       case 'Contains':
  13.         if (rawKey.includes(arg1)) {
  14.           console.log(`${rawKey} contains ${arg1}`);
  15.         } else {
  16.           console.log('Substring not found!');
  17.         }
  18.         break;
  19.       case 'Flip':
  20.  
  21.         const beginIndex = Number(arg2);
  22.         const endIndex = Number(arg3);
  23.         const sliceStr = rawKey.slice(beginIndex, endIndex);
  24.  
  25.         if (arg1 === 'Upper') {
  26.           rawKey = rawKey.slice(0, beginIndex) + sliceStr.toUpperCase() + rawKey.slice(endIndex);
  27.           console.log(rawKey)
  28.         } else if (arg1 === 'Lower') {
  29.           rawKey = rawKey.slice(0, beginIndex) + sliceStr.toLowerCase() + rawKey.slice(endIndex);
  30.           console.log(rawKey)
  31.         }
  32.  
  33.  
  34.         break;
  35.       case 'Slice':
  36.         const bIndex = Number(arg1);
  37.         const eIndex = Number(arg2);
  38.         rawKey.slice(bIndex, eIndex);        
  39.         rawKey = rawKey.slice(0, bIndex) + rawKey.slice(eIndex);
  40.         console.log(rawKey)
  41.         break;
  42.  
  43.       default:
  44.         break;
  45.     }
  46.  
  47.  
  48.     inputLine = args.shift();
  49.   }
  50.  
  51.   console.log(`Your activation key is: ${rawKey}`);
  52. }
Add Comment
Please, Sign In to add comment