使用 compose 时 Ramda 未定义

Ramda undefined when using compose

我正在完成第五章的 "Mostly Adequate Guide" 练习。我用

导入了 Ramda
var R = require('ramda');

并编写了辅助函数:

var _average = function(xs) {
    return R.reduce(R.add, 0, xs) / xs.length;
};

一样单独使用效果很好
_average(R.map(R.prop('dollar_value'), cars));

但是当我这样写的时候:

var averageDollarValue = R.compose(_average(), R.map(R.prop('dollar_value')));

我收到以下错误

Uncaught TypeError: Cannot read property 'reduce' of undefined

有人可以解释为什么会这样吗?

你作文中的括号意味着你在作文中调用函数_average。尝试删除它们,这对我有用。这是代码片段。

var averageDollarValue = R.compose(_average, R.map(R.prop('dollar_value')));