-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
49 lines (39 loc) · 1.09 KB
/
index.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import fs from 'node:fs'
function access() {
fs.readFile('./log.txt', 'utf8', (err, data) => {
if (err) {
console.error(err)
return
}
let passwordFalsy = 0
let passwordTruthy = 0
function isOnlyLettersAndNumbers(text: string) {
return /^[a-z0-9]+$/.test(text)
}
function isUpNumber(text: string) {
return /^(?:0*1*2*3*4*5*6*7*8*9*)$/.test(text)
}
function isUpLetter(text: string) {
return /^(?:a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*)$/.test(text)
}
function isValidPassword(password: string) {
const parts = password.match(/^([0-9]*)([a-z]*)$/)
if (!parts) return false
const [_, numbers, letters] = parts
return isUpNumber(numbers) && isUpLetter(letters)
}
for (const code of data.split('\n')) {
if (isOnlyLettersAndNumbers(code)) {
if (isValidPassword(code)) {
passwordTruthy++
} else {
passwordFalsy++
}
} else {
passwordFalsy++
}
}
console.log(`${passwordTruthy}true${passwordFalsy}false`)
})
}
access()