Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 10, 2013 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5552552 to your computer and use it in GitHub Desktop.
Save tmcw/5552552 to your computer and use it in GitHub Desktop.
// 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