Advertisement
Guest User

Password Validator

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