fs.readFile('./input.txt', (error, data) => {
if(error)
console.log(error);
const input = data.toString();
const dataArray = input.split(/[\n\r ]+/);
const lastItem = dataArray.length;
let accumulator = 0;
let counter = 0;
for(let i=0; i<lastItem-1; i++) {
let tempArray = dataArray[i];
let splitArray = tempArray.split('x');
let a = splitArray[0];//length
let b = splitArray[1];//width
let c = splitArray[2];//height
let d = a<b? (b<c?c:b) : (a<c?c:a);
let output = 0;
if(d === a)
output = (2*b + 2*c + a*b*c);
else if(d === b)
output = (2*a + 2*c + a*b*c);
else
output = (2*b + 2*a + a*b*c);
accumulator += output;
}})
Here is the code snippet along with input values provided for reference:
Input: 3x11x24 13x5x19 1x9x27
I've encountered issues with comparisons in my code, particularly when trying to determine the largest of three numbers. Despite expecting true results like 'console.log(a < b)' returning false for 3 and 11, I'm unsure why my logic isn't functioning as intended. Your assistance would be greatly appreciated, especially since I'm using node.js to run this code. Thank you for your help.