Liliana797979

password reset1 - final exam

Jul 22nd, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function solve(input) {
  4.     let pass = input.shift();
  5.  
  6.     for(const line of input) {
  7.         const tokens = line.split(' ');
  8.         const cmd = String(tokens[0]);
  9.  
  10.         if(cmd === 'TakeOdd') {
  11.             let raw = ''
  12.             for(let i = 0; i < pass.length; i++) {
  13.                 if(i % 2 !== 0) {
  14.                     raw += pass[i];
  15.                 }
  16.             }
  17.             pass = raw;
  18.             console.log(pass);
  19.  
  20.         } else if (cmd === 'Cut') {
  21.             const index = tokens[1];
  22.             const length = tokens[2];
  23.             const substr = pass.substr(index, length);
  24.             pass = pass.replace(substr, '');
  25.             console.log(pass);
  26.  
  27.         } else if (cmd === 'Substitute') {
  28.             const substr = tokens[1];
  29.             const substitute = tokens[2];
  30.  
  31.             if(!pass.includes(substr)) {
  32.                 console.log("Nothing to replace!");
  33.             } else {
  34.                 pass = pass.split(substr).join(substitute);
  35.                 console.log(pass);
  36.             }
  37.  
  38.         }
  39.  
  40.     }
  41.     console.log(`Your password is: ${pass}`);  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment