【发布时间】:2018-11-18 20:26:48
【问题描述】:
我正试图围绕 Ramda.js,但我被卡住了。我有一个看起来像这样的数组:
const state = [
{
itemId: 112,
animations: [{id: 1}, {id:2}],
classes: ['animated']
},
{
itemId: 121,
animations: [{id:2}],
classes: ['animated']
}
]
我的目标是创建一个函数
removeAnimation(121, 2, state);
...会返回:
const state = [
{
itemId: 112,
animations: [{id: 1}, {id:2}],
classes: ['animated']
},
{
itemId: 121,
animations: [],
classes: []
}
]
所以该函数根据指定itemId的对象内部的指定id移除动画obj,如果animations数组中没有更多对象,它也会移除animated中的字符串classes列表。
这是我走了多远:
const removeAnimationFromItem = R.curry((itemId, animId, state) => {
return R.map(
R.when(
R.propEq('itemId', itemId), [--This is where I'm stuck--]
), state)
})
感谢您的宝贵时间。
【问题讨论】:
-
你想只使用 ramda.js 来做这个吗?
-
是的。使用香草 ES6,这不会花很长时间。我正在尝试练习函数式编程,并且该应用程序已经有 Ramda.js。
标签: javascript arrays ramda.js