Please consider this function, which currently helps handle all variants of "hints" employed by the user:
function _searchHints(txt, hints) { //search for text in given hints, which may be array of strings or comma separated string
if (!txt || !hints) return; //validate both are given - otherwise quick return
if (typeof hints === "string") hints = hints.split(", "); //from here on only an array is allowed
for (var i = 0; i < hints.length; i++) //search hints array
if (txt.iO(hints[i])) return true; //if single hint found within passed text - return true
}
...which is far from ideal, mostly because the internal array is built on the fly each time.
Instead, I would like to replace this helper function with an object-oriented and thus persistent little class, that has two phases:
Initialisation: Create the internal array - only once
Search hints: Determine, whether the URL passed is addressed by any hints specified in the previous step by the user
I've made this draft:
function Hints(hints) { var myHints = (typeof hints === 'string' && hints.length > 0) ? hints.split(", ") : false; //hints are passed as a comma separated string
this.find = function(txt) {
if (!txt || !myHints) return; //validate both are given - otherwise quick return
return myHints.some( function(h) { return txt.iO(h) } ); // iterate through items, on first positive match return true
};
}
Please consider this function, which currently helps handle all variants of "hints" employed by the user:
...which is far from ideal, mostly because the internal array is built on the fly each time.
Instead, I would like to replace this helper function with an object-oriented and thus persistent little class, that has two phases:
I've made this draft:
...which has been successfully tested against:
Please see changes, where calling code has also been updated...
Closing, because several tests were performed successfully. Will re-open if any test fails...