Last active
August 23, 2017 04:26
-
-
Save zz85/cfbc590647b9cfd73089e530b25df217 to your computer and use it in GitHub Desktop.
Simple Counter
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
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