lilobase
1/29/2016 - 2:23 PM

surface.js

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 = (acc, side) => (acc + side) ;

function total_surface_area(boxes) {
  return boxes.reduce((acc, box) => {
    const box_sides = sides(box)
    return acc + box_sides.reduce(box_surface) * 2 + Math.min(...box_sides);
  }, 0);
}

console.log(total_surface_area(boxes));