Skip to content

Instantly share code, notes, and snippets.

@zz85
Last active August 23, 2017 04:26
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 zz85/cfbc590647b9cfd73089e530b25df217 to your computer and use it in GitHub Desktop.
Save zz85/cfbc590647b9cfd73089e530b25df217 to your computer and use it in GitHub Desktop.
Simple Counter
class Counter {
constructor() {
this.map = new Map();
}
add(key) {
this.map.set(key, this.map.has(key) ? this.map.get(key) + 1 : 1);
}
print() {
// TODO fix me
console.log(this.map)
}
count() {
return this.map.size;
}
}
// test
counter = new Counter;
counter.add('a')
counter.add('a')
counter.add('a')
counter.add('b')
counter.print()
console.log(counter.count())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment