Created
August 19, 2014 15:16
-
-
Save silviorelli/e8f98261d3328e1dabae to your computer and use it in GitHub Desktop.
CoffeeScript AND between two arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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