Currently i am doing multiple string match in javascript, i know most of us are familiar with javascript every method, as a result it provides true or false. Is there any other way in performance wise better than this.
'javascript code'.split(' ').every(val => 'you should code in javascript'.includes(val));
Actual string length of mine is very big, it becomes performance bottleneck when i using this js every method.
You could just check if the set of words is a subset of the larger set of words..
const needles = 'javascript code'.split(' ');
const haystack = 'you should code in javascript'.split(' ');
const is_subSet = (a, b) => {
const setA = new Set(a), setB = new Set(b);
return [...setA].every(v => setB.has(v));
};
is_subSet(needles, haystack);