Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!