I want to make a function to check if all elements in an array are present in another. I have tried to do this:
function includesAll (needles, haystack) {
return needles.every((needle) => {
return haystack.includes(needle)
})
}
However, when I test for this function for the empty array as needles, like this: includesAll([], [1]), it returns true, whereas I'm expecting false (because [1].includes([]) returns false). Why does this happen? And can you write a correct function (one that reflects the behavior of include, but for an array instead of an element)?