I have two Arrays of strings, and I would like to find the set of strings not in the intersection of both. The equivalent of SETXOR in MATLAB is what I want: http://www.mathworks.com/help/techdoc/ref/setxor.html
I'm using the term set interchangeably with Array.
Of course, I could have just as easily written my own in the time taken to form this question, but I thought I should ask.
array1 + array2 - (array1 & array2)
It was shorter, than to write a question...
By the way, Ruby has a class Set, so better not to use this word as a synonym to an Array.
Yes, as Nakilon says, Set.
require 'set'
s = Set.new('a'..'f')
a = ['f','d','e','e','h','i'] #or any enum
p s ^ a #=> #<Set: {"h", "i", "a", "b", "c"}>
You can always just do
(array0 - array1) + (array1 - array0)
a = [1, 2, 3, 4, 5]
b = [2, 5, 8]
(a - b) + (b - a)
# => [1, 3, 4, 8]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With