- I am using the php underscore
- Use closures and assign them to variables
- Put variables at begin of the function, main code will after
////////
- Must be
function sumPrice($items) {
$sum = function ($memo, $item) {
return $memo + $item['price'];
}
/////////
return Underscore::from($items)->reduce($sum, 0)->value();
}
- Don't
function sumPrice($items) {
return Underscore::from($items)->reduce(function ($memo, $item) {
return $memo + $item['price'];
}, 0)->value();
}