-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.ts
34 lines (30 loc) · 879 Bytes
/
04.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
import {loadData} from '../shared/utils';
export type DataType = Array<string>;
/* istanbul ignore next */
export const parse = async (): Promise<Array<DataType>> =>
(await loadData(2017, 4)).split('\n').map(row => row.split(' '));
export const part1 = (data: Array<DataType>): number => {
return data.filter(phrase => {
const words: Array<string> = [];
for (let word of phrase) {
if (words.includes(word)) {
return false;
}
words.push(word);
}
return true;
}).length;
};
export const part2 = (data: Array<DataType>): number => {
return data.filter(phrase => {
const words: Array<string> = [];
for (let word of phrase) {
const sortedWord = word.split('').sort().join('');
if (words.includes(sortedWord)) {
return false;
}
words.push(sortedWord);
}
return true;
}).length;
};