I want to check if it is possible to make a recipe with the ingredients that are inputted. I tried swapping out the arrays but it does not match properly then. Is there any other way to check if the recipe can be made?
recipes = [
{
"category": "Dezerti",
"ingredients": ["10 belanaca", "500 g secera", "2 kasike sirceta", "2 kasike gustina", "10 zumanaca", "10 kasika secera", "5 kasika gustina", "2 kesice vanile", "8 dl mleka", "250 g putera", "200 g mlevenih oraha", "250 ml slatke pavlake", "250 ml slatke pavlake"],
"link": "https://www.recepti.com/kuvar/torte/52213-torta-spanski-vetar",
"name": "Torta španski vetar (3)"
},
{
"category": "Dezerti",
"ingredients": ["200 g mlevena plazma"],
"link": "Test",
"name": "Test"
},
];
This is what I've tried:
const options = {
includeScore: true,
keys: ['ingredients'],
includeMatches: true,
threshold: 0.4,
}
class Ingredient {
constructor(ingredients) {
this.ingredients = ingredients;
}
}
function canBeMade(recipe, ingredients) {
var p = recipe.ingredients;
recipe.ingredients = ingredients;
ingredients = p;
ingObj = [];
res = [];
res.push(recipe);
fuse = new Fuse(res, options);
for (let i = 0; i < ingredients.length; i++) {
ingObj.push(new Ingredient(ingredients[i]));
}
result = fuse.search({
$and: ingObj
});
if (result[0] != undefined)
return true;
return false;
}
returns false
console.log(canBeMade(recipes[1], ["plazma"]));