Skip to content

Instantly share code, notes, and snippets.

@lilobase
Created January 29, 2016 14:11
Show Gist options
  • Save lilobase/f98262bcb673cf65d1a1 to your computer and use it in GitHub Desktop.
Save lilobase/f98262bcb673cf65d1a1 to your computer and use it in GitHub Desktop.
const boxes = [[2, 3, 4], [1, 1, 10]];
const sides = ([a, b, c], acc = []) => (acc.length == 3) ? acc : sides([b, c, a], acc.concat([a * b]));
const box_surface = sides => sides.reduce((acc, side) => (acc + side)) * 2 + Math.min(...sides);
function total_surface_area(boxes) {
return boxes.reduce((acc, box) => {
return acc + box_surface(sides(box));
}, 0);
}
console.log(total_surface_area(boxes));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment