-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpassword.js
More file actions
30 lines (30 loc) · 741 Bytes
/
password.js
File metadata and controls
30 lines (30 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function getPasswordStrength(passwords, common_words) {
// Write your code here
const commonWords = new Set(common_words);
const result = passwords.map((password) => {
if (commonWords.has(password)) {
return "weak";
}
for (let i = 0; i < password.length; i++) {
for (let j = i + 1; j <= password.length; j++) {
if (commonWords.has(password.slice(i, j))) {
return "weak";
}
}
}
if (password.match(/^[0-9]+$/)) {
return "weak";
}
if (
password == password.toUpperCase() ||
password == password.toLowerCase()
) {
return "weak";
}
if (password.length < 6) {
return "weak";
}
return "strong";
});
return result;
}