Using array methods to solve this issue.
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 .split(/[,()]/) .map((el) => el.trim().toLowerCase()) .some((el) => gluten.includes(el)); }
- function glutenDetector(ingredients){
var gluten = [- const gluten = [
- "wheat",
- "wheat flour",
- "triticale",
- "barley",
- "rye",
- "brewer's yeast",
- "malt",
- "wheatberries",
- "durum",
- "emmer",
- "semolina",
- "spelt",
- "farina",
- "farro",
- "graham",
- "kamut",
- "einkorn"
- ];
var glutenDetect = false;var ingredientsList = ingredients.split(',');ingredientsList.forEach(function(ingredient){var ingredientClean = ingredient.trim().toLowerCase();gluten.forEach(function(glutenIngredient){if(ingredientClean.indexOf(glutenIngredient) !== -1){glutenDetect = true;}});});return glutenDetect;- return ingredients
- .split(/[,()]/)
- .map((el) => el.trim().toLowerCase())
- .some((el) => gluten.includes(el));
- }