【发布时间】:2016-09-17 19:52:26
【问题描述】:
人, 我在使用这个算法时遇到了一些问题。
我正在使用 Redux,但我认为这与这个问题无关。基本上,这段代码中的 console.log 语句只返回一个对象,就像它应该返回的那样,但是函数 A 返回两个对象的数组(即使是在函数 C 中没有通过测试的那个)
我将函数分成 3 个部分,看看这是否能帮助我修复它,但我仍然无法弄清楚。
有什么建议吗?
const A = (state) => {
// looks through an array and passes down a resource
return state.resources.locked.filter((resource) => {
return B(state, resource);
})
};
// looks through an array and passes down a building
const B = (state, resource) => {
return state.bonfire.allStructures.filter((building) => {
return C(building, resource);
})
};
// checks if building name and resource requirment are the same, and if building is unlocked
// then returns only that one
const C = (building, resource) => {
if (building.unlocked && building.name == resource.requires.structure) {
console.log(resource);
return resource;
}
}
【问题讨论】:
-
请提供样品
state。
标签: javascript ecmascript-6 redux