Advertisement
Guest User

Untitled

a guest
Nov 5th, 2020
350
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.   let commandLine = input.shift();
  4.  
  5.  
  6.   while (commandLine !== "Done") {
  7.     if (commandLine.includes("TakeOdd")) {
  8.       let newPass = "";
  9.       for (let i = 0; i < password.length; i++) {
  10.         if (i % 2 === 1) {
  11.           newPass += password[i];
  12.         }
  13.       }
  14.       password = newPass;
  15.       console.log(password);
  16.  
  17.     } else if (commandLine.includes("Substitute")) {
  18.       let [command, substring, substitute] = commandLine.split(' ');
  19.  
  20.       if (password.includes(substring)) {
  21.         while (password.includes(substring)) {
  22.           password = password.replace(substring, substitute);
  23.         }
  24.  
  25.         console.log(password);
  26.       } else {
  27.         console.log(`Nothing to replace!`);
  28.       }
  29.  
  30.     } else if (commandLine.includes("Cut")) {
  31.       let [command, index, length] = commandLine.split(' ');
  32.       index = Number(index);
  33.       length = Number(length);
  34.       let cut = password.substr(index, length);
  35.       password = password.replace(cut, '');
  36.       console.log(password);
  37.  
  38.     }
  39.  
  40.  
  41.     commandLine = input.shift();
  42.   }
  43.  
  44.   console.log(`Your password is: ${password}`);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement