Difference of Volumes of Cuboids

Instructions: In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids' volumes regardless of which is bigger. For example, if the parameters passed are ([2, 2, 3], [5, 4, 1]), the volume of a is 12 and the volume of b is 20. Therefore, the function should return 8. Your function will be tested with pre-made examples as well as random ones. Thoughts: I destructure the a and b array and find there volume. Create an id/else with the condition of volA - volB > 0. Solution: function findDifference(a, b) { const [f1, s1, t1] = a; const [f2, s2, t2] = b; const volA = f1 * s1 * t1; const volB = f2 * s2 * t2; if (volA - volB > 0) console.log(volA - volB); else console.log(volB - valA); } This is a CodeWars Challenge of 8kyu Rank (https://www.codewars.com/kata/58cb43f4256836ed95000f97/train/javascript)

Apr 20, 2025 - 17:34
 0
Difference of Volumes of Cuboids

Instructions:
In this simple exercise, you will create a program that will take two lists of integers, a and b. Each list will consist of 3 positive integers above 0, representing the dimensions of cuboids a and b. You must find the difference of the cuboids' volumes regardless of which is bigger.

For example, if the parameters passed are ([2, 2, 3], [5, 4, 1]), the volume of a is 12 and the volume of b is 20. Therefore, the function should return 8.

Your function will be tested with pre-made examples as well as random ones.

Thoughts:

  1. I destructure the a and b array and find there volume.
  2. Create an id/else with the condition of volA - volB > 0.

Solution:
function findDifference(a, b) {
const [f1, s1, t1] = a;
const [f2, s2, t2] = b;
const volA = f1 * s1 * t1;
const volB = f2 * s2 * t2;
if (volA - volB > 0) console.log(volA - volB);
else console.log(volB - valA);
}

This is a CodeWars Challenge of 8kyu Rank (https://www.codewars.com/kata/58cb43f4256836ed95000f97/train/javascript)