We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 35e8a30 commit 377ecf0Copy full SHA for 377ecf0
1 file changed
2025/day/5/ingredients.ts
@@ -1,9 +1,8 @@
1
export function parseDatabase(text: string) {
2
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
- });
+ const freshIdRanges = top.matchAll(/(?<start>\d+)-(?<end>\d+)/g)
+ .map(({ groups: { start, end } = {} }) => ({ start: +start, end: +end }))
+ .toArray();
7
const availableIds = bottom.split("\n").map(Number);
8
return { freshIdRanges, availableIds };
9
}
0 commit comments