Skip to content

Instantly share code, notes, and snippets.

@lilobase
Last active July 30, 2016 06:51
Show Gist options
  • Save lilobase/bd4030054313143784a9 to your computer and use it in GitHub Desktop.
Save lilobase/bd4030054313143784a9 to your computer and use it in GitHub Desktop.
const boxes = [[2, 3, 4], [1, 1, 10]];
function total_surface_area(boxes) {
let total_surface = 0;
for (let box of boxes) {
const sides = [box[0]*box[1], box[1]*box[2], box[2]*box[0]];
const smallest_side = Math.min(...sides);
const box_surface = (sides[0] + sides[1] + sides[2])*2 + smallest_side;
total_surface = total_surface + box_surface;
}
return total_surface;
}
console.log(total_surface_area(boxes));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment