Browse Source

Add file for common functions

ApisNecros 3 months ago
parent
commit
cb9f5b92fa
1 changed files with 8 additions and 0 deletions
  1. 8 0
      common.js

+ 8 - 0
common.js

@@ -0,0 +1,8 @@
+import fs from "node:fs";
+
+export function loadInput(dayNumber, parsingFunction, literalPath = false) {
+    let filePath = literalPath ? dayNumber : `./inputs/day_${dayNumber}.input`;
+    const data = fs.readFileSync(filePath, "utf8");
+
+    return typeof parsingFunction == "function" ? parsingFunction(data) : data;
+}