[Guide] Data Structures: Create a Set Class (#34434)

* feat: added solution

* fix: solution

* fix: changed expression to be be more readable

* fix: formatting
This commit is contained in:
Aditya
2018-11-25 23:26:33 +05:30
committed by Christopher McCormack
parent 9fb1d9f49c
commit c3155c4f5b
2 changed files with 37 additions and 4 deletions

View File

@ -70,7 +70,18 @@ function Set() {
```js
function Set() {var collection = []; this.has = function(e){return(collection.indexOf(e) !== -1);};this.values = function() {return collection;};this.add = function(element) {if (!this.has(element)) {collection.push(element);return true;} else {return false;}};}
function Set() {
var collection = [];
this.has = function(element) {
return (collection.indexOf(element) !== -1);
};
this.values = function() {
return collection;
};
this.add = function(el) {
return this.has(el) ? false : Boolean(collection.push(el));
}
}
```
</section>