Add utilty function to check for substring in array

This commit is contained in:
Joshua Colvin 2017-01-07 12:53:49 -05:00
parent 7f0d4fff1b
commit 957244583c

View file

@ -139,3 +139,20 @@ var cloneCssStyles = function(svg, classes){
};
exports.cloneCssStyles = cloneCssStyles;
/**
* @function isSubstringInArray
* Detects whether a substring in present in a given array
* @param {string} str The substring to detect
* @param {array} arr The array to search
* @returns {number} the array index containing the substring or -1 if not present
**/
var isSubstringInArray = function (str, arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].match(str)) return i;
}
return -1;
};
exports.isSubstringInArray = isSubstringInArray;