Advertisement
Neri0817

01. Password Reset

Apr 1st, 2022
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function resetPswrd(input) {
  2.   let str = input.shift().split("");
  3.   let password = [];
  4.  
  5.   while (input[0] !== "Done") {
  6.     let line = input.shift().split(" ");
  7.     let command = line.shift();
  8.  
  9.     if (command === "TakeOdd") {
  10.       for (let i = 0; i < str.length; i++) {
  11.         if (i % 2 !== 0) {
  12.           password.push(str[i]);
  13.         }
  14.       }
  15.       password = password.join("");
  16.       console.log(password);
  17.     }
  18.  
  19.     if (command === "Cut") {
  20.       let index = Number(line.shift());
  21.       let length = Number(line.shift());
  22.       let remove = password.substr(index, length);
  23.       password = password.replace(remove, "");
  24.       console.log(password);
  25.     }
  26.  
  27.     if (command === "Substitute") {
  28.       let substring = line.shift();
  29.       let substitute = line.shift();
  30.  
  31.       if (password.includes(substring)) {
  32.         password = password.split(substring).join(substitute);
  33.         console.log(password);
  34.       } else {
  35.         console.log("Nothing to replace!");
  36.       }
  37.     }
  38.   }
  39.   console.log(`Your password is: ${password}`);
  40. }
  41. resetPswrd([
  42.   "Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr",
  43.   "TakeOdd",
  44.   "Cut 15 3",
  45.   "Substitute :: -",
  46.   "Substitute | ^",
  47.   "Done",
  48. ]);
  49.  
  50. resetPswrd([
  51.   "up8rgoyg3r1atmlmpiunagt!-irs7!1fgulnnnqy",
  52.   "TakeOdd",
  53.   "Cut 18 2",
  54.   "Substitute ! ***",
  55.   "Substitute ? .!.",
  56.   "Done",
  57. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement