-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.js
41 lines (34 loc) · 936 Bytes
/
helper.js
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
39
40
41
import { readFile, access } from "fs/promises";
export async function loadData({ day, dataType = "sample" }) {
const data = await readFile(`./${day}/${dataType}.txt`, "utf-8");
return data.split("\n");
}
export async function fileExists(filename) {
try {
await access(filename);
return true;
} catch (err) {
return false;
}
}
export async function argsChecker(args) {
if (args.length === 0) {
console.log("Please provide a day number");
process.exit(1);
}
let dataType = "input";
if (args[1] === "sample") {
dataType = "sample";
}
return { dataType };
}
export async function partRunner({ part, input }) {
console.time(part.name);
const result = await part({ input });
console.timeEnd(part.name);
console.log(result);
return result;
}
export function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}