-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathproblem6.js
More file actions
34 lines (28 loc) · 820 Bytes
/
problem6.js
File metadata and controls
34 lines (28 loc) · 820 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
33
34
function problem6(forms) {
const emailSet = new Set();
function getchars(nickname) {
const name = new Set();
for (let i = 0; i < nickname.length - 1; i++) {
name.add(nickname.slice(i, i + 2));
}
return Array.from(name);
}
for (let i = 0; i < forms.length; i++) {
const [email1, nickname1] = forms[i];
const name1Substrings = getchars(nickname1);
for (let j = 0; j < forms.length; j++) {
if (i === j) continue;
const [email2, nickname2] = forms[j];
for (const substring of name1Substrings) {
const regExp = new RegExp(substring);
if (regExp.test(nickname2)) {
emailSet.add(email1);
emailSet.add(email2);
break;
}
}
}
}
return Array.from(emailSet).sort();
}
module.exports = problem6;