Last active
April 8, 2017 18:43
-
-
Save DavidMetcalfe/4d3d68395d7e1b9b8aef69b2264ff667 to your computer and use it in GitHub Desktop.
Find match between string and array, stop after first positive result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @description determine if an array contains one or more items from another array. | |
* @param {array} needle the array providing items to check for in the haystack. | |
* @param {array} haystack the array to search. | |
* @return {boolean} true|false if haystack contains at least one item from arr. | |
*/ | |
var findOne = function (needle, haystack) { | |
return needle.some(function (v) { | |
return haystack.indexOf(v) >= 0; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment