-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
38 lines (31 loc) · 1 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
function containsAtLeastThreeVowels(str: string): boolean {
return /([aeiou].*?){3,}/.test(str);
}
function containsAtLeastOneRepetitiveLetter(str: string): boolean {
return /([a-z])\1/.test(str);
}
function containingStrings(str: string): boolean {
return /(ab|cd|pq|xy)/.test(str);
}
function containsAtLeastTwoTwoLettersWithoutOverlap(str: string): boolean {
return /([a-z][a-z]).*\1/.test(str);
}
function containsAtLeastOneRepetitiveLetterWithLetterInBetween(str: string): boolean {
return /([a-z])[a-z]\1/.test(str);
}
function part1(strings: string[]): number {
return strings.filter(
(string) =>
containsAtLeastThreeVowels(string) &&
containsAtLeastOneRepetitiveLetter(string) &&
!containingStrings(string),
).length;
}
function part2(strings: string[]): number {
return strings.filter(
(string) =>
containsAtLeastTwoTwoLettersWithoutOverlap(string) &&
containsAtLeastOneRepetitiveLetterWithLetterInBetween(string),
).length;
}
export { part1, part2 };