Created
August 2, 2016 19:10
-
-
Save amacdougall/de81ddbf777f1375854da97725d0a9eb to your computer and use it in GitHub Desktop.
Very basic set-like collection, supporting only contains/add/remove.
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
| function is(a) { | |
| return b => a === b; | |
| } | |
| function isNot(a) { | |
| return b => a !== b; | |
| } | |
| class SimpleMembershipSet { | |
| constructor(values = null) { | |
| this.values = values || []; | |
| } | |
| contains(v) { | |
| return this.values.find(is(v)); | |
| } | |
| add(v) { | |
| if (!this.values.find(is(v))) { | |
| this.values.push(v); | |
| } | |
| } | |
| remove(v) { | |
| this.values = this.values.filter(isNot(v)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment