Array.forEach((element) => {
recipes.forEach((curr, index) => {
found = true;
item = element;
if (!curr.ingredients.includes(element)) found = false;
if (index + 1 === recipes.length && found === false) {
console.log(element, false);
} else if (index + 1 === recipes.length && found === true) {
console.log(element, true);
foundItem = element;
}
});
});
return foundItem;
Hello, guys... I am trying to debug such code... What is happening is that, as you can see in the picture down below, My code is returning me "açúcar", "calabresa", and "cerveja". Image where you can see the output from my console
However, it is not what I mean since I am looping through a JSON list that happens to have ingredients for several different recipes... Such as follows
"recipes": [
{
"id": "00832498-3acc-4bde-9d89-77eacef26680",
"title": "Excelente pudim de milho",
"ingredients": [
"abóbora",
"aveia",
"azeite",
"açúcar",
"cerveja",
"frango",
"milho",
"morango",
"vinho"
],
"price": 78.53
},
{
"id": "008b345d-8f7c-427d-988b-4f238b8315f2",
"title": "Excelente bolo de azeite",
"ingredients": [
"abóbora",
"aveia",
"azeite",
"açúcar",
"frango",
"vinho"
],
"price": 82.55
},
{
"id": "00d14194-f223-447e-86a0-b535c451d53f",
"title": "Exuberante coxinha de vinho",
"ingredients": [
"abóbora",
"azeite",
"açúcar",
"calabresa",
"cerveja",
"chuchu",
"frango",
"morango",
"uva",
"vinho"
],
What I want to get is açucar, since is the only ingredient which is present in all of the recipes... As for me, it seems like there is some sort of cache-related problem here