You are viewing a single comment's thread. Return to all comments →
Javascript
function surfaceArea(A) { const topAndBottom = (A[0].length * A.length) * 2; let bothSides = A.map((row) => row.reduce((acc, side) => acc + side), 0).filter((sideRow, index) => [0, A.length - 1].indexOf(index) > -1).reduce((acc, sum) => acc + sum, 0); bothSides = A.length === 1 ? bothSides * 2 : bothSides; let frontAndBackSides = A.map((row) => row[0] + row[A[0].length - 1]).reduce((row, acc) => acc + row, 0); for (let x = 0; x < A[0].length; x++) { for (let y = 0; y < A.length; y++) { if (y>0) { bothSides += Math.abs(A[y][x] - A[y-1][x]); } if (x>0) { frontAndBackSides += Math.abs(A[y][x] - A[y][x-1]); } } } return frontAndBackSides + bothSides + topAndBottom; }
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
Javascript