- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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
,创建一个 bool 函数,说明给定的人是否写过任何文章。
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)}
最佳答案
Compose 返回一个函数,因此您需要将 articles
传递给该函数。 Compose 会将 articles
传递给 getNames
,并将 getNames
的结果传递给 contains(name)
(其中还返回一个函数),它将处理作者姓名,并返回 bool 值 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>
关于javascript - 在这种情况下如何作曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55826887/
我对一切都很陌生——F#、一般的编程和这个社区。我是一名数学家,在本科期间短暂接触过计算机科学。我正在尝试在 F# 和 "F# Cheat Sheet" 中完成一些任务在不解释重复的情况下展示了看似三
我已经实现了一个可以添加到 Actors 的 Listenable/Listener 特性。我想知道是否可以将这种风格的特征附加到 Actor 而不必显式调用 listenerHandler 方法?
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
我是一名优秀的程序员,十分优秀!