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.
My code:
function findDifference(a, b) {
let aResult = 1;
let bResult = 1;
for (let i = 0; i < a.length; i++){
aResult *= a[i];
}
for (let j = 0; j < b.length; j++){
bResult *= b[j];
}
if (aResult > bResult){
return aResult-bResult;
}else{
return bResult-aResult;
}
}
function find_difference(a, b) {
return Math.abs(a[0]*a[1]*a[2]-b[0]*b[1]*b[2]);
}
New things I learned today: