Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marka2g/b45fca67a00258e268d0c492084d5d08 to your computer and use it in GitHub Desktop.

Select an option

Save marka2g/b45fca67a00258e268d0c492084d5d08 to your computer and use it in GitHub Desktop.
Ruby opposite of array intersection
# Ruby opposite of array intersection... or maybe the method is missing from my brain bc not enough coffee
# http://twitter.com/soawesomeman/status/8035087261
def awesome(ar_1, ar_2)
(ar_1 + ar_2) - (ar_1 & ar_2)
end
awesome([1,2,3,4], [3,4,5,6]) # => [1, 2, 5, 6]
# bonus code from @texel
# http://twitter.com/texel/status/8035307156
(a - (a & b)) | (b - (a & b)) # => nice one!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment