Created
January 29, 2016 14:36
-
-
Save lilobase/385c59a2ee4548f4b48f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const boxes = [[2, 3, 4], [1, 1, 10]]; | |
const apply = (f, i) => (f(i)); | |
const sides = ([a, b, c], acc = []) => (acc.length == 3) ? acc : sides([b, c, a], acc.concat([a * b])); | |
const box_surface = (acc, side) => (acc + side) ; | |
function total_surface_area(boxes) { | |
return boxes.reduce((acc, box) => | |
apply((b) => acc + b.reduce(box_surface) * 2 + Math.min(...b), 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