ers、 私はこのアルゴリズムに問題があります。2つのオブジェクトを返すJavascriptフィルタ
私はReduxを使用していますが、この問題には本当に関係しません。基本的には、このコードのconsole.logステートメントは、必要に応じてただ1つのオブジェクトを返しますが、関数Aは2つのオブジェクトの配列を返します(関数Cでテストに合格しなかった場合でも)。
Iそれを修正するのに役立つかどうかを確認するために関数を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;
}
}
:あなただけ評価される式を持って矢印の機能にショートカット表記を使用することができます
も注意してください。 –