Skip to content

Commit 377ecf0

Browse files
committed
refactor(2025/day/5/ingredients): use regexp
1 parent 35e8a30 commit 377ecf0

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

2025/day/5/ingredients.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
export function parseDatabase(text: string) {
22
const [top, bottom] = text.split("\n\n");
3-
const freshIdRanges = top.split("\n").map((text: string) => {
4-
const [start, end] = text.split("-").map(Number);
5-
return { start, end };
6-
});
3+
const freshIdRanges = top.matchAll(/(?<start>\d+)-(?<end>\d+)/g)
4+
.map(({ groups: { start, end } = {} }) => ({ start: +start, end: +end }))
5+
.toArray();
76
const availableIds = bottom.split("\n").map(Number);
87
return { freshIdRanges, availableIds };
98
}

0 commit comments

Comments
 (0)