[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:
committed by
Christopher McCormack
parent
9fb1d9f49c
commit
c3155c4f5b
@ -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>
|
||||
|
Reference in New Issue
Block a user