Originally Posted by
King Mir
A way to approach this problem more broadly is to identify known recursive algorithms that can be applied to the situation. Such algorithms include: accumulate/fold, which applies a function to total all the elements together in to one result; map/for each/transform, which applies a function to each element using; and filter/grep, which gets rid of all elements that do not satisfy a boolean condition function.
For for example you can alternatively use this set of algorithms:
For each element A in array one, filter list two on the condition of each element being equal to A.
Then count the number of elements in the resultant list using accumulate (or more directly if you can figure out how).