maymunskoa

02. Password (Final Exam 090819)

Mar 23rd, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let count = Number(input.shift());
  3.   let pattern = /^(\S+)>(?<nums>[0-9]{3})\|(?<low>[a-z]{3})\|(?<upper>[A-Z]{3})\|(?<symbol>[^<>]{3})<\1$/gm;
  4.  
  5.   for (const line of input) {
  6.     if (Array.from(line.matchAll(pattern)).length > 0) {
  7.       let result = Array.from(line.matchAll(pattern))[0].groups;
  8.       console.log(
  9.         `Password: ${result.nums}${result.low}${result.upper}${result.symbol}`
  10.       );
  11.     } else {
  12.       console.log("Try another password!");
  13.     }
  14.   }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment