The chooseRecipe function should compare the arrays in bakeryA and bakeryB with the ingredients of each recipe. If bakeryA and bakeryB each have an ingredient for a recipe, then the name of the recipe should be printed. In this case, Persian Cheesecake is what should be printed. However, it keeps returning an empty array.
I understand that I'm starting off with an empty array, but shouldn't suitableRecipe.push(recipes[i].name); be taking care of that?
Would appreciate any guidance, or suggestions for a better way to do this.
let bakeryA = ['saffron', 'eggs', 'tomato paste', 'coconut', 'custard'];
let bakeryB = ['milk', 'butter', 'cream cheese'];
let recipes = [
{
name: 'Coconut Sponge Cake',
ingredients: ['coconut', 'cake base']
},
{
name: 'Persian Cheesecake',
ingredients: ['saffron', 'cream cheese']
},
{
name: 'Custard Surprise',
ingredients: ['custard', 'ground beef']
}
];
const chooseRecipe = function(bakeryA, bakeryB, recipes) {
let suitableRecipe = [];
for (let i = 0; i < recipes.length; i++) {
for (let j = 0; j < recipes[i].ingredients.length; j++) {
for (let k = 0; k < bakeryA.length; k++) {
if (bakeryA[k] === recipes[i].ingredients[j]) {
for (let l = 0; l < bakeryB.length; l++) {
for (let m = 0; m < recipes[i].ingredients; m++) {
if (bakeryB[l] === recipes[i].ingredients[m]) {
suitableRecipe.push(recipes[i].name);
}
}
}
}
}
}
}
return suitableRecipe;
}
console.log(chooseRecipe(bakeryA, bakeryB, recipes));
for (let m = 0; m < recipes[i].ingredients; m++) {is missing.lengthforingredients?