【发布时间】:2021-04-19 02:07:36
【问题描述】:
我正在开发一个 Ionic 应用程序,该应用程序包含成分数组和一个带有食谱的服务,看起来像这样->
所以我需要将配料与食谱相匹配。我开始这样做了:
this.truelist = [...this.spliterStrIngredients()]; // my arrayof ingredients
const nbIngredients = this.truelist.length;
console.log('true list = ' + this.truelist);
let match = 0 ;
this.recipeList.forEach((key => {
key.ingreds.forEach(ingrRecipe => {
this.truelist.forEach((ingrSelct , index) => {
if (ingrSelct === ingrRecipe)
{
match ++;
}
if (match >= this.truelist.length ) {
this.recipeMatch.push(key.name);
match = 0;
}
});
});
}));
console.log(this.recipeMatch);
}
所以当我选择完全相同的食谱时它可以工作,但我希望更灵活,例如我有意大利面+奶酪+胡萝卜的数组,但我可以搭配 carbonara。
感谢您的帮助
【问题讨论】:
-
我无法弄清楚你的灵活匹配规则。如果你能说出灵活匹配的确切规则就更好了。我不太了解如何制作 Carbonara(笑)
-
所以 Carbonara = [pasta ,cheese ] 但即使我有更多的配料,我也会匹配。例如,我的配料中有 [意大利面、奶酪、其他配料更多]。我的意思是,如果我的阵列中有好的成分和更多成分,它就是匹配的。如果很清楚,我不知道
标签: javascript angular typescript ionic-framework types