瀏覽代碼

Update parseInput to return array of Moons

ApisNecros 4 月之前
父節點
當前提交
af3665bbaf
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      12/12_1.js

+ 4 - 3
12/12_1.js

@@ -1,5 +1,6 @@
 const util = require("util");
 const Vector3 = require("./Vector3");
+const Moon = require("./Moon");
 
 const input = [
     "<x=14, y=15, z=-2>",
@@ -30,7 +31,7 @@ function calculateGravity(moonA, moonB) {
 
 /**
  * @param {string[]} inputs The day's input
- * @returns {Vector3[]} An array of Vector3's representing the positions of moons
+ * @returns {Moon[]} An array of Moon objects
  */
 function parseInput(inputs) {
     const moons = [];
@@ -39,10 +40,10 @@ function parseInput(inputs) {
     for (const position of inputs) {
         // eslint-disable-next-line no-shadow-restricted-names
         const [undefined, x, y, z] = position.match(parseRegex);
-        moons.push(new Vector3(parseInt(x, 10), parseInt(y, 10), parseInt(z, 10)));
+        moons.push(new Moon(new Vector3(parseInt(x, 10), parseInt(y, 10), parseInt(z, 10))));
     }
 
     return moons;
 }
 
-console.log(util.inspect(parseInput(input)));
+// console.log(util.inspect(parseInput(input)));