There is a third way to look at this solution, which directly answers the question and does not require the use of sets:
r = (ab) | (ba)
(ab) will give you what is in array a, but not b:
ab => [3]
(ba) will give you what is in array b, but not:
ba => []
OR - subtracting two arrays will give you the final result of something that is not in both arrays:
r = ab | ba => [3]
Another example might make this even clearer:
a = [1,2,3] => [1, 2, 3] b = [2,3,4] => [2, 3, 4] ab => [1] ba => [4] r = (ab) | (ba) => [1, 4]
source share