We want to use the fp.reduce function to compute the average of a list of numbers, as in:
> average( [ 2, 4, 1, 5 ] ) 3
The following implementation will work as long as you replace the question marks on line 4 with the correct expression.
1. var average = function (ns) {
2. var p = fp.reduce (
3. function (x,y) {
4. ????????????????????????
5. },
6. ns,
7. [ 0 , 0 ]
8. );
9. return fp.div(fp.hd(p),fp.hd(fp.tl(p)));
10. };
Which one of the following expressions must replace the question marks above?
What is the formula for computing the average of a list of numbers?
What is the semantics of the two arguments of the anonymous function in the code above?
What is the structure of the accumulator in this case?