1.9 KiB
1.9 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d8254367417b2b2512c70 | Create and Add to Sets in ES6 | 1 | 在ES6中创建和添加集 |
Description
Set
现在包含了您手动编写的许多操作。我们来看看:创建一个新的空集: var set = new Set();
您可以使用值创建一个集合: var set = new Set(1);
您可以使用数组创建一个集合: var set = new Set([1, 2, 3]);
创建集合后,可以使用add
方法添加所需的值: var set = new Set([1,2,3]);提醒一下,集合是一种不能包含重复值的数据结构:
set.add([4,5,6]);
var set = new Set([1,2,3,1,2,3]);
// set仅包含[1,2,3]
Instructions
1, 2, 3, 'Taco', 'Cat', 'Awesome'
Tests
tests:
- text: '您的<code>Set</code>应该只包含值<code>1, 2, 3, Taco, Cat, Awesome</code> 。'
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 <code>Set</code> should only contain the values <code>1, 2, 3, Taco, Cat, Awesome</code>.");'
Challenge Seed
function checkSet() {
var set = new Set([1, 2, 3, 3, 2, 1, 2, 3, 1]);
// change code below this line
// change code above this line
console.log(set);
return set;
}
checkSet();
Solution
// solution required