.symmetricDifference()
webBlaster589342 total contributions
Published Jan 28, 2023
Contribute to Docs
The .symmetricDifference()
method returns a new set with the elements that are either in the set or in the given sequence, but not in both. In other words, it returns a new set with all the elements from two sets that do not overlap.
Syntax
setName.symmetricDifference(otherSetName)
The otherSetName
parameter is a finite sequence of elements.
Example
The following example shows the elements that aren’t common to each set:
let food: Set = ["Apple", "Banana", "Orange", "Peach"]let colors = ["Green", "Blue", "Orange", "Peach"]let eitherFoodOrColor = food.symmetricDifference(colors)
This will display the following:
["Banana", "Green", "Apple", "Blue"]
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.