Skip to content

Instantly share code, notes, and snippets.

@silviorelli
Created August 19, 2014 15:16
Show Gist options
  • Save silviorelli/e8f98261d3328e1dabae to your computer and use it in GitHub Desktop.
Save silviorelli/e8f98261d3328e1dabae to your computer and use it in GitHub Desktop.
CoffeeScript AND between two arrays
array_and = (ary1, ary2) ->
result = []
seen = {}
i = 0
length = ary1.length
while i < length
item = ary1[i]
unless seen[item]
j = 0
length2 = ary2.length
while j < length2
item2 = ary2[j]
if not seen[item2] and (item is item2)
seen[item] = true
result.push item
j++
i++
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment