I understand I can search for an ( a single item in an array) several different ways. Iterate with for loops, foreach, recursive structures etc, but I am not trying to do that as I am searching for multiple items at a time.
For instance I may have an array of objects with this model:
people: [{name: "howdy", date: 2/2, sex: male}, {name: "jack", date: 3/3, sex: male}]
I want to know if howdy and jack are there at the same time. or maybe I want to know if howdy and jack are both in the array of people. Or maybe I want to know if howdy and Jack are both there by searching through the people array for matches based on birthday and sex.
I know how to do it one at a time but not searching by multiple values. I found this on stackover flow but I don't understand it. Is there a simpler way to search an array to find matches in the array based on multiple keys?
This did not work:
function containsAll(needles, haystack){
for(var i = 0, len = needles.length; i <len; i++){
if($.inArray(needles[i], haystack) == -1_ return false
}
return true;
}
containsAll([34, 78, 89], [78, 67, 34, 99, 56, 89]); // true
containsAll([34, 78, 89], [78, 67, 99, 56, 89]); // false
containsAll([34, 78, 89], [78, 89]); // false