Skip to content

Instantly share code, notes, and snippets.

@DavidMetcalfe
Last active April 8, 2017 18:43
Show Gist options
  • Save DavidMetcalfe/4d3d68395d7e1b9b8aef69b2264ff667 to your computer and use it in GitHub Desktop.
Save DavidMetcalfe/4d3d68395d7e1b9b8aef69b2264ff667 to your computer and use it in GitHub Desktop.
Find match between string and array, stop after first positive result
/**
* @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