-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstrong-password.js
More file actions
32 lines (27 loc) · 874 Bytes
/
strong-password.js
File metadata and controls
32 lines (27 loc) · 874 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
31
32
/*
Title: Strong Password
Difficulty: Easy
Score: 15
Link: https://www.hackerrank.com/challenges/strong-password
*/
module.exports = function passwordStrengthMinimumNumber(n, password) {
const STRONG_LENGTH = 6;
const missingChars = STRONG_LENGTH - n;
let score = 0;
const passwordAsArray = Array.from(password);
const hasNumber = passwordAsArray.some(char => "0123456789".includes(char));
const hasLowerCase = passwordAsArray.some(char =>
"abcdefghijklmnopqrstuvwxyz".includes(char)
);
const hasUpperCase = passwordAsArray.some(char =>
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(char)
);
const hasSpecialChar = passwordAsArray.some(char =>
"!@#$%^&*()-+".includes(char)
);
if (!hasNumber) score++;
if (!hasLowerCase) score++;
if (!hasUpperCase) score++;
if (!hasSpecialChar) score++;
return Math.max(score, missingChars);
};