In JavaScript, how do I test that one array has the elements of another array?
arr1 = [1, 2, 3, 4, 5] [8, 1, 10, 2, 3, 4, 5, 9].function_name(arr1) # => t
You can use array.indexOf():
pseudocode:
function arrayContainsAnotherArray(needle, haystack){ for(var i = 0; i < needle.length; i++){ if(haystack.indexOf(needle[i]) === -1) return false; } return true; }