Browse Source

Update parseInput to return array of Moons

ApisNecros 4 months ago
parent
commit
af3665bbaf
1 changed files with 4 additions and 3 deletions
  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)));