1.6 KiB
1.6 KiB
id | title | challengeType |
---|---|---|
587d8255367417b2b2512c72 | Use .has and .size on an ES6 Set | 1 |
Description
var set = new Set([1,2,3]);
The .has method will check if the value is contained within the set.
var hasTwo = set.has(2);
The .size method will return an integer representing the size of the Set
var howBig = set.size;
Instructions
Tests
tests:
- text: <code>checkSet([4, 5, 6], 3)</code> should return [ false, 3 ]
testString: 'assert((function(){var test = checkSet([4,5,6], 3); return DeepEqual(test, [ false, 3 ]);})(), "<code>checkSet([4, 5, 6], 3)</code> should return [ false, 3 ]");'
Challenge Seed
function checkSet(arrToBeSet, checkValue){
// change code below this line
// change code above this line
}
checkSet([ 1, 2, 3], 2); // Should return [ true, 3 ]
Solution
function checkSet(arrToBeSet, checkValue){
var set = new Set(arrToBeSet);
var result = [
set.has(checkValue),
set.size
];
return result;
}