Task
Given two sets A and B, compute 



(
A
∖
B
)
∪
(
B
∖
A
)
.


{\displaystyle (A\setminus B)\cup (B\setminus A).}



That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B.

In other words: 



(
A
∪
B
)
∖
(
A
∩
B
)


{\displaystyle (A\cup B)\setminus (A\cap B)}

 (the set of items that are in at least one of A or B minus the set of items that are in both A and B).

Optionally, give the individual differences (



A
∖
B


{\displaystyle A\setminus B}

 and 



B
∖
A


{\displaystyle B\setminus A}

) as well.



Test cases
A = {John, Bob, Mary, Serena}
B = {Jim, Mary, John, Bob}



Notes
 If your code uses lists of items to represent sets then ensure duplicate items in lists are correctly handled. For example two lists representing sets of a = ["John", "Serena", "Bob", "Mary", "Serena"] and b = ["Jim", "Mary", "John", "Jim", "Bob"] should produce the result of just two strings: ["Serena", "Jim"], in any order.
 In the mathematical notation above A \ B gives the set of items in A that are not in B; A ∪ B gives the set of items in both A and B, (their union); and A ∩ B gives the set of items that are in both A and B (their intersection).


 
#!/bin/ksh
 
# Symmetric difference - enumerate the items that are in A or B but not both.
 
#	# Variables:
#
typeset -a A=( John Bob Mary Serena )
typeset -a B=( Jim Mary John Bob )
 
#	# Functions:
#
#	# Function _flattenarr(arr, sep) - flatten arr into string by separator sep
#
function _flattenarr {
	typeset _arr ; nameref _arr="$1"
	typeset _sep ; typeset -L1 _sep="$2"
	typeset _buff
	typeset _oldIFS=$IFS ; IFS="${_sep}"
 
	_buff=${_arr[*]}
	IFS="${_oldIFS}"
	echo "${_buff}"
}
 
#	# Function _notin(_arr1, _arr2) - elements in arr1 and not in arr2
#
function _notin {
	typeset _ar1 ; nameref _ar1="$1"
	typeset _ar2 ; nameref _ar2="$2"
	typeset _i _buff _set ; integer _i
 
	_buff=$(_flattenarr _ar2 \|)
	for((_i=0; _i<${#_ar1[*]}; _i++)); do
		[[ ${_ar1[_i]} != @(${_buff}) ]] && _set+="${_ar1[_i]} "
	done
	echo ${_set% *}
}
 
 ######
# main #
 ######
 
AnB=$(_notin A B) ; echo "A - B   = ${AnB}"
BnA=$(_notin B A) ; echo "B - A   = ${BnA}"
echo "A xor B = ${AnB} ${BnA}"