Created
April 24, 2014 16:02
-
-
Save mondalaci/11259937 to your computer and use it in GitHub Desktop.
StringSet class in JavaScript
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
"use strict"; | |
var StringSet = /* StringSet */ function() { | |
this.set = {}; | |
this.add = /* bool */ function(/* String */ string) { | |
var contains = this.contains(string); | |
this.set[string] = true; | |
return !contains; | |
}; | |
this.remove = /* bool */ function(/* String */ string) { | |
var contains = this.contains(string); | |
delete this.set[string]; | |
return contains; | |
}; | |
this.contains = /* bool */ function(/* String */ string) { | |
return string in this.set; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment