isContainedIn
Checks if the elements of the first array are contained in the second one regardless of order.
- Use a
for...of
loop over aSet
created from the first array. - Use
Array.prototype.some()
to check if all distinct values are contained in the second array. - Use
Array.prototype.filter()
to compare the number of occurrences of each distinct value in both arrays. - Return
false
if the count of any element is greater in the first array than the second one,true
otherwise.