在这种情况下如何作曲

How to compose in this situation

var articles = [
  {
    title: 'Everything Sucks',
    author: { name: 'Debbie Downer' }
  },
  {
    title: 'If You Please',
    author: { name: 'Caspar Milquetoast' }
  }
];

var names = _.map(_.compose(_.get('name'), _.get('author'))) 
// returning ['Debbie Downer', 'Caspar Milquetoast']

现在根据上面给定的 articles 和函数 names,创建一个布尔函数,说明给定的人是否写过任何文章。

isAuthor('New Guy', articles) //false
isAuthor('Debbie Downer', articles)//true

我在下面的尝试

var isAuthor = (name, articles) => {
    return _.compose(_.contains(name), names(articles))
};

但是它在 jsbin 上失败并出现以下错误。也许有人可以尝试解释我的尝试出了什么问题,以便我可以从错误中吸取教训

Uncaught expected false to equal function(n,t){return r.apply(this,arguments)}

编写 return 一个函数,因此您需要将 articles 传递给该函数。 Compose 会将 articles 传递给 getNames,并将 getNames 的结果传递给 contains(name)(这也是 return 一个函数),后者将处理作者姓名, 和 return 布尔值 result:

const { map, path, compose, contains } = R

const getNames = map(path(['author', 'name']))

const isAuthor = (name) => compose(
  contains(name),
  getNames
)

const articles = [{"title":"Everything Sucks","author":{"name":"Debbie Downer"}},{"title":"If You Please","author":{"name":"Caspar Milquetoast"}}]

console.log(isAuthor('New Guy')(articles)) //false
console.log(isAuthor('Debbie Downer')(articles)) //true
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script>