diff --git a/2.Ex1 Password validation.js b/2.Ex1 Password validation.js index cd93dbf..b92374a 100644 --- a/2.Ex1 Password validation.js +++ b/2.Ex1 Password validation.js @@ -32,9 +32,24 @@ The belows are invalids because - "tytT3729." is valid as an individual password, but already appeared in the password array - "12qw" doesn't contain uppercase letter, special symbol and less than 5 characters long */ +const passwords = ["tytT3729.", "fhD!yrjj", "ttkTuwer3", "DVYYEYY!5", "qwbfj76%", "Pl3!", "tytT3729.", "12qw"]; -function validatePasswords(passwords) {} +var conditions = /(?=\S*\d)(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[#!.$%])\S{5,}/; +let validatePasswords = passwords + +.map((password, index) => { + + if (conditions.test(password) && passwords.indexOf(password) === index) { + return true + } else { + return false + } + }); + + console.log(validatePasswords) + +//expected results is [4] is false /* ======= TESTS - DO NOT MODIFY ===== */ const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"]; diff --git a/practice2.js b/practice2.js new file mode 100644 index 0000000..770a006 --- /dev/null +++ b/practice2.js @@ -0,0 +1,23 @@ +let passwords = ["tytT3729.", "fhD!yrjj", "ttkTuwer3", "DVYYEYY!5", "qwbfj76%", "Pl3!", "tytT3729.", "12qw", "tytT3728.", "DVYYEYY!5", "tkTuwer3!"]; + +var conditions = /(?=\S*\d)(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[#!.$%])\S{5,}/; + +let validatePasswords = passwords + +.map((password, index) => { + + if (conditions.test(password) && passwords.indexOf(password) === index) { + return true + } else { + return false + } + }); + + console.log(validatePasswords); + + //1. regex test +// .map((password) => regex.test(password)) + + //2. Check duplicate + // let results = passwords + // .map((password, index) => passwords.indexOf(password) === index) \ No newline at end of file