Files
freeCodeCamp/curriculum/challenges/spanish/08-coding-interview-prep/data-structures/create-and-add-to-sets-in-es6.spanish.md
2018-10-08 13:34:43 -04:00

2.1 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d8254367417b2b2512c70 Create and Add to Sets in ES6 Crear y agregar a conjuntos en ES6 1

Description

Ahora que ha trabajado con ES5, va a realizar algo similar en ES6. Esto será considerablemente más fácil. ES6 contiene una estructura de datos incorporada Set muchas de las operaciones que ha escrito a mano se incluyen ahora para usted. Echemos un vistazo: Para crear un nuevo conjunto vacío: var set = new Set(); Puede crear un conjunto con un valor: var set = new Set(1); Puede crear un conjunto con una matriz: var set = new Set([1, 2, 3]); Una vez que haya creado un conjunto, puede agregar los valores que desee utilizando el método de add :
var set = new Set([1, 2, 3]);
set.add([4, 5, 6]);
Como recordatorio, un conjunto es una estructura de datos que no puede contener valores duplicados:
var set = new Set([1, 2, 3, 1, 2, 3]);
// set contains [1, 2, 3] only

Instructions

Para este ejercicio, devuelva un conjunto con los siguientes valores: 1, 2, 3, 'Taco', 'Cat', 'Awesome'

Tests

tests:
  - text: &#39;Tu <code>Set</code> solo debe contener los valores <code>1, 2, 3, Taco, Cat, Awesome</code> &#39;.
    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

function checkSet(){var set = new Set([1,2,3,'Taco','Cat','Awesome']);
return set;}