2021-06-15 00:49:18 -07:00
---
id: 587d8255367417b2b2512c72
2021-10-27 15:10:57 +00:00
title: Usare .has e .size su un set ES6
2021-06-15 00:49:18 -07:00
challengeType: 1
forumTopicId: 301717
dashedName: use--has-and--size-on-an-es6-set
---
# --description--
2021-10-27 15:10:57 +00:00
Diamo un'occhiata ai metodi .has e .size disponibili sull'oggetto Set ES6.
2021-06-15 00:49:18 -07:00
2021-10-27 15:10:57 +00:00
Per prima cosa, crea un Set ES6
2021-06-15 00:49:18 -07:00
```js
var set = new Set([1,2,3]);
```
2021-10-27 15:10:57 +00:00
Il metodo .has controllerà se il valore è contenuto all'interno del set.
2021-06-15 00:49:18 -07:00
```js
var hasTwo = set.has(2);
```
2021-10-27 15:10:57 +00:00
Il metodo .size restituirà un numero intero rappresentante la dimensione del Set
2021-06-15 00:49:18 -07:00
```js
var howBig = set.size;
```
# --instructions--
2021-10-27 15:10:57 +00:00
In questo esercizio passeremo un array e un valore alla funzione checkSet(). La tua funzione dovrebbe creare un set ES& dall'argomento array. Scopri se il set contiene il valore argomento. Trova la dimensione del set. E restituire questi due valori in un array.
2021-06-15 00:49:18 -07:00
# --hints--
2021-10-27 15:10:57 +00:00
`checkSet([4, 5, 6], 3)` dovrebbe restituire [ false, 3 ]
2021-06-15 00:49:18 -07:00
```js
assert(
(function () {
var test = checkSet([4, 5, 6], 3);
return DeepEqual(test, [false, 3]);
})()
);
```
# --seed--
## --seed-contents--
```js
function checkSet(arrToBeSet, checkValue){
// Only change code below this line
// Only change code above this line
}
```
# --solutions--
```js
function checkSet(arrToBeSet, checkValue){
var set = new Set(arrToBeSet);
var result = [
set.has(checkValue),
set.size
];
return result;
}
```