I am having trouble understanding why one arrow function will return an array of items while the other doesn't (it's the same function, just in a different format).
Goal: This program is supposed to filter through a JSON file to find cocktails that have every ingredient (not strictly just the ingredients specified) specified by an array of strings.
Let me share some context as to what one of the JSON file objects looks like (out of over 400+):
{
"strGlass": "White Wine Glass",
"idDrink": "15346",
"strCreativeCommonsConfirmed": "No",
"strCategory": "Cocktail",
"strInstructionsIT": "Miscela con ghiaccio.\r\nServire in un bicchiere da vino.\r\nGuarnire con una carota.",
"strInstructions": "Blend with ice. Serve in a wine glass. Garnish with carrot.",
"strDrink": "155 Belmont",
"Ingredients": [
{
"Measurement": "1 shot ",
"Ingredient": "Dark rum"
},
{
"Ingredient": "Light rum",
"Measurement": "2 shots "
},
{
"Measurement": "1 shot ",
"Ingredient": "Vodka"
},
{
"Measurement": "1 shot ",
"Ingredient": "Orange juice"
}
],
"dateModified": "2016-10-05 12:36:28",
"strDrinkThumb": "https://www.thecocktaildb.com/images/media/drink/yqvvqs1475667388.jpg",
"strAlcoholic": "Alcoholic",
"strInstructionsDE": "Mit Eis vermischen. In einem Weinglas servieren. Mit Karotte garnieren."
}
And the array I'm using looks like this:
let Filterable_Drinks = reactive([]);
let Ingredients_Searched_For = reactive(["vodka", "lemonade"]);
Here's the first format:
Filterable_Drinks.length = 0;
const items = DRINKS.filter(cocktail => Ingredients_Searched_For.every(ing => cocktail.Ingredients.find(cocIng => cocIng.Ingredient.toLowerCase().includes(ing.toLowerCase()))))
Filterable_Drinks.push(...items);
console.log(Filterable_Drinks);
And here is the second format:
Filterable_Drinks.length = 0;
const items = DRINKS.filter((cocktail) => {
Ingredients_Searched_For.every((ing) => {
cocktail.Ingredients.find(cocIng => cocIng.Ingredient.toLowerCase().includes(ing.toLowerCase()))
})
})
Filterable_Drinks.push(...items);
console.log(Filterable_Drinks);
It seems to be the same thing, but the second one returns an empty array as the first one doesn't.
What's the difference between the two different formats of the same code?