Created
January 29, 2016 13:50
-
-
Save lilobase/75ca331ba2a7196dd5b2 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 sides = (box) => [box[0]*box[1], box[1]*box[2], box[2]*box[0]]; | |
const smallest_side = (sides) => Math.min(...sides); | |
const box_surface = (sides) => ((sides[0] + sides[1] + sides[2]) * 2) + smallest_side(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