Skip to content

Instantly share code, notes, and snippets.

View lilobase's full-sized avatar

Arnaud LEMAIRE lilobase

View GitHub Profile
@lilobase
lilobase / gist:8823878
Created February 5, 2014 13:44
PhpUnit tips
<?php
//read a protected/private attribute
\PHPUnit_Framework_Assert::readAttribute($object, 'protected_attr');
<?php
namespace Silex\Provider;
use Silex\Application;
use Silex\SilexEvents;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
const boxes = [[2, 3, 4], [1, 1, 10]];
function total_surface_area(boxes) {
let total_surface = 0;
for (let box of boxes) {
const sides = [box[0]*box[1], box[1]*box[2], box[2]*box[0]];
const smallest_side = Math.min(...sides);
const box_surface = (sides[0] + sides[1] + sides[2])*2 + smallest_side;
total_surface = total_surface + box_surface;
const boxes = [[2, 3, 4], [1, 1, 10]];
function total_surface_area(boxes) {
return boxes.reduce((acc, box) => {
const sides = [box[0]*box[1], box[1]*box[2], box[2]*box[0]];
const smallest_side = Math.min(...sides);
const box_surface = ((sides[0] + sides[1] + sides[2]) * 2) + smallest_side;
return acc + box_surface;
}, 0);
}
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);
@lilobase
lilobase / sides.js
Last active January 29, 2016 14:01
const old_sides = (box) => [box[0]*box[1], box[1]*box[2], box[2]*box[0]];
const sides = ([a, b, c], acc = []) =>
(acc.length == 3) ? acc : sides([b, c, a], acc.concat([a * b]));
const old_box_surface = (sides) => ((sides[0] + sides[1] + sides[2]) * 2) + smallest_side(sides);
const box_surface = (sides) =>
(sides.reduce((acc, side) => (acc + side)) * 2) + smallest_side(sides);
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);
}
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);
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);