Ad

using find breaks execution once it finds one gluten ingredient. same as someone with celiac disease.

Code
Diff
  • function glutenDetector(ingredients){
      const gluten = [
      "wheat",
      "wheat flour",
      "triticale",
      "barley",
      "rye",
      "brewer's yeast",
      "malt",
      "wheatberries",
      "durum",
      "emmer",
      "semolina",
      "spelt",
      "farina",
      "farro",
      "graham",
      "kamut",
      "einkorn"
      ];
      
      return !!ingredients
        .toLowerCase()
        .split(" ")
        .find(i => gluten.indexOf(i) > -1);
    }
    • function glutenDetector(ingredients){
    • const gluten = [
    • "wheat",
    • "wheat flour",
    • "triticale",
    • "barley",
    • "rye",
    • "brewer's yeast",
    • "malt",
    • "wheatberries",
    • "durum",
    • "emmer",
    • "semolina",
    • "spelt",
    • "farina",
    • "farro",
    • "graham",
    • "kamut",
    • "einkorn"
    • ];
    • return gluten.some(g=>ingredients.includes(g.toUpperCase()));
    • return !!ingredients
    • .toLowerCase()
    • .split(" ")
    • .find(i => gluten.indexOf(i) > -1);
    • }