Last active
January 1, 2016 22:59
-
-
Save liamgriffiths/8213549 to your computer and use it in GitHub Desktop.
set data structure built on top of js object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Set = function() { | |
this._items = {}; | |
}; | |
Set.prototype = { | |
values: function() { | |
return Object.keys(this._items); | |
}, | |
insert: function(val) { | |
if (this._items[val]) return false; | |
this._items[val] = true; | |
return true; | |
}, | |
remove: function(val) { delete(this._items[val]); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment