|
@@ -19,21 +19,23 @@ const tests = parseInput([
|
|
/**
|
|
/**
|
|
* Find the gravitational influence two moons have on each other
|
|
* 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) {
|
|
function calculateGravity(moonA, moonB) {
|
|
// The gravitational pull on Moon A caused by Moon B
|
|
// 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
|
|
// 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
|
|
// 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
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|