浏览代码

Update calculateGravity to work with Moon class

ApisNecros 4 月之前
父节点
当前提交
76603389a4
共有 1 个文件被更改,包括 9 次插入7 次删除
  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;
 }
 
 /**