Exploring arrays and comparing their values. Here is an example of an array with values:
arr1 = [1,5,6,7,3,8,12];
Now we have another array that we want to compare with:
arr2 = [3,5,7];
We need to check if all the values in arr2 are present in arr1.
function containsValue(n){
for(var i=0; i<this.length; i++){
if(this[i] == n)
return true;
}
return false;
}
arr1.containsValue("12"); //would work
// How can we efficiently check if arr1 contains all values in arr2?
The current code works for individual numbers, but how can we modify it to handle arrays and efficiently compare them?