Advertisement
Guest User

PasswodRTeset

a guest
Aug 9th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function passValid(input) {
  2.     let password = input.shift();
  3.     let line = input.shift();
  4.     while (line != 'Done') {
  5.         let [command, firstArg, secondArg] = line.split(' ');
  6.         let tempPassword = '';
  7.         switch (command) {
  8.             case 'TakeOdd':
  9.                 for (let i = 1; i < password.length; i += 2) {
  10.                     tempPassword += password[i];
  11.                 }
  12.                 console.log(tempPassword);
  13.                 password = tempPassword;
  14.                 break;
  15.             case 'Cut':
  16.                 let index = Number(firstArg);
  17.                 let length = Number(secondArg);
  18.                 let substring = password.substring(index, index + length);
  19.                 password = password.replace(substring, '');
  20.                 console.log(password);
  21.                 break;
  22.             case 'Substitute':
  23.                 tempPassword = password;
  24.                 while (tempPassword.includes(firstArg)) {
  25.                     tempPassword = tempPassword.replace(firstArg, secondArg);
  26.                 }
  27.                 if (password.includes(firstArg)) {
  28.                     console.log(tempPassword);
  29.                 } else {
  30.                     console.log('Nothing to replace!');
  31.                 }
  32.                 password = tempPassword;
  33.         }
  34.         line = input.shift();
  35.     }
  36.     console.log(`Your password is: ${password}`);
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement