-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (30 loc) · 1.13 KB
/
index.js
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
const fetchData = async () => {
const data = await fetch('https://codember.dev/data/database_attacked.txt');
const text = await data.text();
const files = text.split('\n');
resolve(files);
};
const resolve = (files) => {
let invalids = [];
const alphanumeric = /^[a-zA-Z0-9]*$/;
const emailRegex = /^[^@]+@[^@]+.[a-zA-Z]*$/;
files.forEach((element) => {
let idValid = true,
usernameValid = true,
emailValid = true;
const [id, username, email, age, location] = element.split(',');
// id existe y es alfanumérico
id ? (idValid = alphanumeric.test(id)) : (idValid = false);
// username existe y es alfanumérico
username ? (usernameValid = alphanumeric.test(username)) : (usernameValid = false);
// email existe y es valido user@dominio.com
email ? (emailValid = emailRegex.test(email)) : (emailValid = false);
// Encuentra el primer carácter (número o letra) del username de cada usuario inválido.
if (!(idValid && usernameValid && emailValid && age && location)) {
invalids.push(username[0]);
}
});
// youh4v3beenpwnd
return invalids.join('');
};
fetchData();