Arrays intersection is a very slow operation. So, if you work with large arrays then it's best to use hashsets instead.
Here is my intersection implementation using hashsets:
hashset = (elements) ->
return elements unless Array.isArray elements
set = {}
set[e] = true for e in elements
set
intersect = (a, b) ->
s1 = hashset a
s2 = hashset b
s3 = {}
for k of s1
s3[k] = true if s2[k]
s3
arrCompare = (a, b) ->
Object.keys(intersect a, b).length isnt 0
I don't think you actually need it to be asynchronous. If you don't want array operations to block main thread - dispatch them to another process (worker).
Update
Here are some benchmarks with benchmark.js:
arr1 = [1..9999];
arr2 = [9999..99999];
{ name: 'My Code',
mean: 0.004182571958225297 }
{ name: 'Your Code',
mean: 2.1228081478333336 }
{ name: 'askkirati\'s Synchronous Code',
mean: 3.569238156 }
Same benchmark for two string arrays:
arr1 = (Math.random().toString(36).slice(2,12) for i in [1..9999])
arr2 = (Math.random().toString(36).slice(2,12) for i in [1..9999])
{ name: 'My Code',
mean: 0.009257149728395064 }
{ name: 'Your Code',
mean: 1.5913590743333332 }
{ name: 'askkirati\'s Synchronous Code',
mean: 1.418200398 }
I also tried two very huge arrays, but I given up on waiting for all methods to complete:
arr1 = [1..999999]
arr2 = [999999..9999999]
{ name: 'My Code',
mean: 1.6512419735000001 }
As you can see, hashmap intersection works much faster than loops intersection. And it takes only 1.6 seconds on my PC to intersect two 999999 element arrays.