Advertisement
kstoyanov

Password js exam

Aug 14th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const numPass = args.shift();
  3.   const regPat = /(\S+)>(?<password>[0-9]{3}\|[a-z]{3}\|[A-Z]{3}\|[^<>]{3})<\1/g;
  4.  
  5.   for (let index = 0; index < numPass; index++) {
  6.     const element = args[index];
  7.  
  8.     const isOk = element.match(regPat);
  9.  
  10.     if (isOk) {
  11.       const takePassword = regPat.exec(element);
  12.  
  13.       if (takePassword !== null) {
  14.         const { password } = takePassword.groups;
  15.  
  16.         const clearPassword = password.replace(/\|/g, '');
  17.  
  18.         console.log(`Password: ${clearPassword}`);
  19.       }
  20.     } else {
  21.       console.log('Try another password!');
  22.     }
  23.   }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement