I am currently working on an Ionic app that involves an array of ingredients and a service with recipes. You can find the structure of the recipe service here.
My goal is to match the ingredients with the recipes. Currently, I have implemented the following logic:
this.truelist = [...this.spliterStrIngredients()]; // an array of 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);
}
While this method works when selecting the exact recipe, I am looking to make it more flexible. For instance, I would like to be able to match an array of ingredients like pasta+cheese+carrots with a recipe like carbonara.
Any help or suggestions on how to achieve this flexibility would be greatly appreciated.