Answer the question
In order to leave comments, you need to log in
How to check the number of occurrences of one array in another?
Hello. Please help me to resolve the issue. I am a beginner, I just started learning JS, I googled, but I did not find how to solve just such a question.
There are two arrays
arr1 = [1,2,3,4,5,6,7,8,9]
arr2 = [3,4,5]
Answer the question
In order to leave comments, you need to log in
Loop through the first array, and if the current character is equal to the first character from the second array, then start the comparison loop.
Exclusively for JS, there is a bad solution:
arr1.join().match(new RegExp(arr2.join(), "g")).length
Here each array is converted to a string and the number of occurrences is searched.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question