One way to do this is to write your own function and provide a string with logical operators in it, like so:
You can parse out each condition and check if the value is in the source array
var val = [[1,2,"3"], ["4",5,6], [7,8,9]];
var vals = val.reduce((acc, val) => acc.concat(val), []);
function orIncludes(source, testString) {
var orValues = testString.split("||").map(val => {
try {
return JSON.parse(val.trim())
}catch(e) {
return val.trim();
}
});
return orValues.some(val => source.includes(val));
}
console.log(orIncludes(vals, '10 || 12 || 3 || "4"')); // true - matches "4"
console.log(orIncludes(vals, '"3" || 8 || 3 || "4"')); // true - matches "3"
console.log(orIncludes(vals, '"2" || 2 || 5 || "19"')); // true - matches 2
console.log(orIncludes(vals, '10 || 12 || "9" || 4')); // false - no match
An easier way to do this if you don't care about combining ORs and ANDs (which the above would allow you to do if you extended it with &&
) is to simply pass in the individual values as parameters and check those, like so:
var val = [[1, 2, "3"],["4", 5, 6],[7, 8, 9]];
var vals = val.reduce((acc, val) => acc.concat(val), []);
function orIncludes(source, ...testValues) {
return testValues.some(val => source.includes(val));
}
console.log(orIncludes(vals, 10, 12, 3, "4")); // true - matches "4"
console.log(orIncludes(vals, "3", 8, 3, "4")); // true - matches "3"
console.log(orIncludes(vals, "2", 2, 5, "19")); // true - matches 2
console.log(orIncludes(vals, 10, 12, "9", 4)); // false - no match
More specifically for your case:
var vals = val.reduce((acc, val) => acc.concat(val), []);
if (vals.includes("CH Nord Mayenne") && orIncludes(vals, 'Douleur','Psychologie','Nutrition')){
CHNM.addTo(myfrugalmap);
} else {
CHNM.remove();
}