Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Fuse.js checking if array is subarray

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"]));
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda