Skip to content

Instantly share code, notes, and snippets.

@lilobase
Last active January 29, 2016 15:43
Show Gist options
  • Save lilobase/90361561d6dfcc89c317 to your computer and use it in GitHub Desktop.
Save lilobase/90361561d6dfcc89c317 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 total_box_surface = (acc, box) => (b => acc + b.reduce((a, b) => a + b) * 2 + Math.min(...b))(sides(box));
const total_surface_area = boxes => boxes.reduce(total_box_surface, 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