How do I convert the following simple average
function to pointfree form (using Ramda)?
var _average = function(xs) {
return R.reduce(R.add, 0, xs) / xs.length;
};
I've been this for a while now, but the R.divide
function is throwing me off since the numerator and the denominator requires evaluation first
Using R.converge
:
// average :: Array Number -> Number
const average = R.converge(R.divide, [R.sum, R.length]);
Using R.lift
(which a more generally applicable function than R.converge
):
// average :: Array Number -> Number
const average = R.lift(R.divide)(R.sum, R.length);