Explorar o código

Update calculateGravity to work with Moon class

ApisNecros hai 4 meses
pai
achega
76603389a4
Modificáronse 1 ficheiros con 9 adicións e 7 borrados
  1. 9 7
      12/12_1.js

+ 9 - 7
12/12_1.js

@@ -19,21 +19,23 @@ const tests = parseInput([
 /**
  * Find the gravitational influence two moons have on each other
  *
- * @param {Vector3} moonA The first moon to consider
- * @param {Vector3} moonB The second moon to consider
+ * @param {Moon} moonA The first moon to consider
+ * @param {Moon} moonB The second moon to consider
  *
- * @returns {void}
+ * @returns {Vector3} The gravitational influence of Moon B on Moon A
  */
 function calculateGravity(moonA, moonB) {
     // The gravitational pull on Moon A caused by Moon B
-    const gravityA = new Vector3(
+    const gravityDifference = new Vector3(
         // eslint-disable-next-line no-nested-ternary
-        moonB.x > moonA.x ? 1 : (moonB.x < moonA.x ? -1 : 0),
+        moonB.position.x > moonA.position.x ? 1 : (moonB.position.x < moonA.position.x ? -1 : 0),
         // eslint-disable-next-line no-nested-ternary
-        moonB.y > moonA.y ? 1 : (moonB.y < moonA.y ? -1 : 0),
+        moonB.position.y > moonA.position.y ? 1 : (moonB.position.y < moonA.position.y ? -1 : 0),
         // eslint-disable-next-line no-nested-ternary
-        moonB.z > moonA.z ? 1 : (moonB.z < moonA.z ? -1 : 0),
+        moonB.position.z > moonA.position.z ? 1 : (moonB.position.z < moonA.position.z ? -1 : 0),
     );
+
+    return gravityDifference;
 }
 
 /**