Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. class Counter {
  2. constructor() {
  3. this.map = {};
  4. }
  5.  
  6. add(key) {
  7. if (this.map[key]) {
  8. this.map[key]++;
  9. }
  10. else {
  11. this.map[key] = 1;
  12. }
  13. }
  14.  
  15. print() {
  16. console.log(this.map);
  17. }
  18.  
  19. count() {
  20. return Object.keys(this.map).length;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement