Created
October 30, 2011 04:00
-
-
Save adamcarr/1325457 to your computer and use it in GitHub Desktop.
ruby intersection of arrays
This file contains 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
def intersect_arrays(arrays) | |
result = [] | |
init = false | |
massaged_array = arrays.compact.uniq || [] | |
massaged_array.each do |a| | |
unless init | |
result = a | |
init = true | |
else | |
result = result & a | |
end | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment