소스 검색

Add file for common functions

ApisNecros 3 달 전
부모
커밋
cb9f5b92fa
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  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;
+}