I am facing a challenge with comparing two arrays
Array1 = [1,1,1,2,2,2,3,3]
Array2 =[1,1,2,1]
When comparing both arrays, the desired result is True if the number of occurrences of Integer 1 are the same.
Array2 = [1,1,2] //Expecting False
For the above case, the expected result is false because the occurrences of 1 and 2 in Array2 do not match with the occurrences in Array1.
Array2 = [1,1,2,3,1] //Expecting True.
I have attempted a solution but it is not effective for all instances.
function allElementsPresent(first, second) {
return second.every((element) => first.includes(element));
}
Any help or suggestions are greatly appreciated. Thank you in advance!