What's the best method to find any of a list of substrings in a specific string?
This works, but can't be right.
var searchEngines = [
new RegExp("www.google."),
new RegExp("www.yahoo."),
new RegExp("search.yahoo."),
new RegExp("www.bing.")
];
function isSearchEngine(url){
for (let i=0,len=searchEngines.length; i < len; i++){
if (searchEngines[i].exec(url)) {
return true;
}
}
return false;
}
Anything to speed this up, really...
[Edit:] After rooting around I found this:
var searchEngines = [
"www\.google\.",
"www\.yahoo\.",
"search\.yahoo\.",
"www\.bing\.",
"duckduckgo\."
].join('|');
if (excludeSearch) {
read = ! (new RegExp(searchEngines, 'gi')).test(keyword);
}
// After the Map object was released in HTML5 I had this at my disposal as well
const imageExtensions = new Map();
['jpeg', 'jpg', 'jif', 'jfif', 'gif', 'tif', 'tiff', 'png', 'pdf', 'jp2', 'jpx', 'j2k', 'j2c', 'fpx', 'pcd'].forEach(function(e) {
imageExtensions.set(e,true);
});