Created
May 10, 2013 05:24
-
-
Save tmcw/5552552 to your computer and use it in GitHub Desktop.
This file contains 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
// A countSet: a Javascript data structure | |
// I tend to build from scratch often. | |
function countSet() { | |
this.set = {}; | |
} | |
countSet.prototype.incr = function(key) { | |
if (!this.set[key]) this.set[key] = 0; | |
this.set[key]++; | |
return this; | |
}; | |
countSet.prototype.decr = function(key) { | |
if (!this.set[key]) this.set[key] = 0; | |
this.set[key]--; | |
return this; | |
}; | |
countSet.prototype.value = function() { | |
return this.set; | |
}; | |
var set = new countSet(); | |
set.incr('keys').decr('foo').value(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment