Advertisement
Guest User

PassReset

a guest
Nov 4th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. function passwordReset(input) {
  2. let password = input.shift();
  3. let commandLine = input.shift();
  4. let newPass = "";
  5.  
  6. while (commandLine !== "Done") {
  7. if (commandLine.includes("TakeOdd")) {
  8. for (let i = 0; i < password.length; i++) {
  9. if (i % 2 === 1) {
  10. newPass += password[i];
  11. }
  12. }
  13. console.log(newPass);
  14.  
  15. } else if (commandLine.includes("Substitute")) {
  16. let [command, substring, substitute] = commandLine.split(' ');
  17.  
  18. if (newPass.includes(substring)) {
  19. while (newPass.includes(substring)) {
  20. newPass = newPass.replace(substring, substitute);
  21. }
  22.  
  23. console.log(newPass);
  24. } else {
  25. console.log(`Nothing to replace!`);
  26. }
  27.  
  28. } else if (commandLine.includes("Cut")) {
  29. let [command, index, length] = commandLine.split(' ');
  30. index = Number(index);
  31. length = Number(length);
  32. let cut = newPass.substr(index, length);
  33. newPass = newPass.replace(cut, '');
  34. console.log(newPass);
  35.  
  36. }
  37.  
  38.  
  39. commandLine = input.shift();
  40. }
  41.  
  42. console.log(`Your password is: ${newPass}`);
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement