Find the Symmetric Difference
Given two arrays, arr1 and arr2, write a function that returns an array containing their symmetric difference. The symmetric difference between two sets is formed by the elements that are present in one of the sets, but not in both.
[ [ 1, 2, 3 ], [ 2, 3, 4 ] ]
Explanation. 1 and 4 are present only in one of the two arrays.
[ [], [ 1, 2, 3 ] ]
Explanation. All elements are only in the second array.
[ [ 1, 2, 3 ], [ 1, 2, 3 ] ]
Explanation. Both arrays are the same, hence no symmetric difference.
[ [ 1, 2 ], [ 3, 4 ] ]
Explanation. Each element is unique to each array.
Follow-up: Can this function be extended to work with more than two arrays?
Each array can contain integers and/or no repeating elements within the same array. The elements of the resulting array should be returned in ascending order.
- Views
- 3