* Reorganized instruction text on multiple challenges * Fixed spaces * Fixed spaces again * Update curriculum/challenges/english/08-coding-interview-prep/data-structures/add-elements-at-a-specific-index-in-a-linked-list.english.md Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/08-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.english.md Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: added code tags
1.6 KiB
1.6 KiB
id, title, challengeType
| 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;
}