I want to compare one array with another:
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy', 'michael', 'bob'];
I want to detect whether array2 contains a name that isn't found in array1.
array2 can be longer or shorter than array1, in other words, array2 might be missing names or have more names than array1, but array2 cannot have a DIFFERENT name as compared to array1.
So far, I can detect whether array2 is longer than array 1. If it is, it is obviously adding names and is therefore not valid:
if (array1.length < array2.length) {
console.log('no');
}
but I this isn't as precise as it needs to be (if both arrays have an equal number of values, it returns true even if the individual vales don't correlate).
see the following for example scenarios:
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy', 'b', 'paul']; //should not be valid
array1 = ['billy', 'b', 'paul'];
array2 = ['billy', 'bob', 'paul']; //should not be valid
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy', 'michael', 'paul']; //should not be valid
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy', 'bob', 'paul', 'michael']; //should not be valid
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy', 'bob']; //this is valid
array1 = ['billy', 'bob', 'paul'];
array2 = ['billy']; //this is valid
array1 = ['bob', 'bob', 'billy', 'paul'];
array2 = ['paul', 'bob', 'bob', 'bob']; //this IS NOT valid
array1 = ['bob', 'bob', 'billy', 'paul'];
array2 = ['paul', 'bob', 'bob']; //this is valid
I'm assuming I should be using .every() but I am unsure as to how to implement it when comparing two arrays as all the examples I find test values of one array against a single value.
update: Array 2 cannot have more instances of a specific name than array 1, but it can have fewer.