var set = new Object ();En los próximos ejercicios, construiremos un conjunto completo desde cero. Para este ejercicio, cree una función que agregue un valor a nuestra colección de conjuntos siempre que el valor no exista en el conjunto. Por ejemplo:
set.foo = true;
// Ver si existe foo en nuestro set:
console.log (set.foo) // true
this.add = function (element) {La función debe devolver
// algún código para agregar valor al conjunto
}
true
si el valor se agrega exitosamente y false
contrario. Set
debería tener un método add
.
testString: 'assert((function(){var test = new Set(); return (typeof test.add === "function")}()), "Your Set
class should have an add
method.");'
- text: Su método de add
no debe agregar valores duplicados.
testString: 'assert((function(){var test = new Set(); test.add("a"); test.add("b"); test.add("a"); var vals = test.values(); return (vals[0] === "a" && vals[1] === "b" && vals.length === 2)}()), "Your add
method should not add duplicate values.");'
- text: Su método de add
debe devolver true
cuando un valor ha sido agregado exitosamente.
testString: 'assert((function(){var test = new Set(); var result = test.add("a"); return (result != undefined) && (result === true);}()), "Your add
method should return true
when a value has been successfully added.");'
- text: Su método de add
debe devolver false
cuando se agrega un valor duplicado.
testString: 'assert((function(){var test = new Set(); test.add("a"); var result = test.add("a"); return (result != undefined) && (result === false);}()), "Your add
method should return false
when a duplicate value is added.");'
```