Set
so many of the operations you wrote by hand are now included for you. Let's take a look:
To create a new empty set:
var set = new Set();
You can create a set with a value:
var set = new Set(1);
You can create a set with an array:
var set = new Set([1, 2, 3]);
Once you have created a set, you can add the values you wish using the add
method:
var set = new Set([1, 2, 3]);As a reminder, a set is a data structure that cannot contain duplicate values:
set.add([4, 5, 6]);
var set = new Set([1, 2, 3, 1, 2, 3]);
// set contains [1, 2, 3] only
1, 2, 3, 'Taco', 'Cat', 'Awesome'
Set
should only contain the values 1, 2, 3, Taco, Cat, Awesome
.'
testString: 'assert((function(){var test = checkSet(); return (test.size == 6) && test.has(1) && test.has(2) && test.has(3) && test.has("Taco") && test.has("Cat") && test.has("Awesome");})(), "Your Set
should only contain the values 1, 2, 3, Taco, Cat, Awesome
.");'
```