Advertisement
divanov94

Untitled

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