Files
freeCodeCamp/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/use-.has-and-.size-on-an-es6-set.spanish.md
2018-10-08 13:34:43 -04:00

1.7 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d8255367417b2b2512c72 Use .has and .size on an ES6 Set Utilice .has y .size en un conjunto ES6 1

Description

Veamos los métodos .has y .size disponibles en el objeto ES6 Set. Primero, cree un conjunto ES6 var set = new Set([1,2,3]); El método .has comprobará si el valor está contenido dentro del conjunto. var hasTwo = set.has(2); El método .size devolverá un número entero que representa el tamaño del Set var howBig = set.size;

Instructions

En este ejercicio pasaremos una matriz y un valor a la función checkSet (). Su función debe crear un conjunto ES6 a partir del argumento de la matriz. Encuentra si el conjunto contiene el argumento de valor. Encuentra el tamaño del conjunto. Y devuelve esos dos valores en una matriz.

Tests

tests:
  - text: &#39; <code>checkSet([4, 5, 6], 3)</code> debe devolver [false, 3]&#39;
    testString: 'assert(function(){var test = checkSet([4,5,6], 3); 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;
}