I'm facing a challenge in developing a function to search for regex in a cell and return a specific value if the result is found. The function works fine on an individual cell, but I can't seem to get it to work when applying it as an array to cells B1:B10 instead of just B10. My goal is to optimize the function by making it work as an array for faster performance. Whenever I try to apply the pagetype function to an array, I encounter this error message: TypeError: Cannot find function search in object yfhhh. (line 13). I realize that I need to adjust the function to make it compatible with a range of cells but I'm not sure how to do it. Here's my current code:
function pageType(string) {
if (string.map) // Checking if input is an array.
return string.map(page); // Applying recursively over the array.
else {
return page(string);
}
}
function page(url) {
var productpage = /.*\.html.*/
var homepage = /^http:\/\/www\.domain.com\/$/
var categorypage = /^http:\/\/www\.domain\.com\/.*/
if (url.search(categorypage) > -1)
return "Category Page";
if (url.search(productpage) > -1)
return "Product Page";
if (url.search(homepage) > -1)
return "Homepage";
else
return "Brand Page";
}