Guest User

PasswordReset

a guest
Jun 28th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pwReset(input = []) {
  2.     let rawPw = input.shift();
  3.     for (const line of input) {
  4.         let tokens = line.split(' ');
  5.         if (tokens === 'Done') {
  6.             break;
  7.         }
  8.         if (tokens[0] === 'TakeOdd') {
  9.             let newPw = '';
  10.             for (let i = 0; i < rawPw.length; i++) {
  11.                 if (i % 2 !== 0) {
  12.                     newPw += rawPw[i];
  13.                 }
  14.             }
  15.             rawPw = newPw;
  16.             console.log(rawPw);
  17.         } else if (tokens[0] === 'Cut') {
  18.             let index = Number(tokens[1]);
  19.             let length = Number(tokens[2]);
  20.             let firstPart = rawPw.substring(0, index);
  21.             let secondPart = rawPw.substring(index + length);
  22.             rawPw = firstPart + secondPart;
  23.             console.log(rawPw);
  24.         } else if (tokens[0] === 'Substitute') {
  25.             let elToReplace = tokens[1];
  26.             let substitute = tokens[2];
  27.  
  28.             if (rawPw.indexOf(elToReplace) === -1) {
  29.                 console.log('Nothing to replace!');
  30.                 continue;
  31.             } else {
  32.                 while (rawPw.indexOf(elToReplace) >= 0) {
  33.                     rawPw = rawPw.replace(elToReplace, substitute);
  34.                 }
  35.             }
  36.             console.log(rawPw);
  37.         }
  38.     }
  39.     console.log(`Your password is: ${rawPw}`);
  40. }
Add Comment
Please, Sign In to add comment