javascript - 通过 Ramda.js 复合 AND 条件拒绝数组项
问题描述
我想使用库来reject
排列项目。Ramda.js
有必要删除具有两个等于 的道具的项目0
。without lambdas
可以用普通Ramda.js
函数做到这一点吗?
我希望收到带有A, B, C
名称的项目(除了D
、 whereacc
和bal
都等于0
),但我的示例返回A, C
.
const arr = [
{
name: 'A',
acc: 1,
bal: 2,
},
{
name: 'B',
acc: 3,
bal: 0,
},
{
name: 'C',
acc: 0,
bal: 4,
},
{
name: 'D',
acc: 0,
bal: 0,
}
]
const filteredItems = R.reject(
R.and(
R.propEq('acc', 0),
R.propEq('bal', 0)
)
)(arr)
提前感谢您的帮助!
解决方案
使用R.allPass
/ R.both
with R.propEq
is的替代方法R.where
,它采用“规范对象”并在满足所有属性时返回 true。
R.reject(R.where({
acc: R.equals(0),
bal: R.equals(0)
}))
推荐阅读
- javascript - 如何从数组的 for 循环的第一次迭代中删除“未定义”?
- php - 如何使用 PHP 代码或 Shotcode 显示 WooCommerce 下载表
- apache-poi - 任务运行两次时,Apache POI 将数据附加到 xlsx 文件
- javascript - 用 JavaScript 用 Canvas 制作一个弹跳球
- mysql - 如何对巨大的二进制列进行按位运算
- ios - Objective-c 中的通用枚举类型
- python - 如何将 django 查询集转换为字典以用作模板上下文
- c++ - 如何将链接 .lib 构建到 .gyp 文件中
- python - 将列表中的 git 存储库克隆到文件夹
- python - 两个数组的最大总和,从每个数组中选择一个元素,使得它们的索引相差 3